Swiftpack.co - miquido/Aegithalos as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by miquido.
miquido/Aegithalos 2.3.1
Function composition for functional scared. The project was made by Miquido. https://www.miquido.com/
⭐️ 9
🕓 2 years ago
iOS macOS tvOS
.package(url: "https://github.com/miquido/Aegithalos.git", from: "2.3.1")

Aegithalos is a library focused on composition of mutating functions. It is useful for preparing repeatable and composable setup for any types i.e views or network requests.

Instalation

Easiest way to use Aegithalos is to add it as you Swift package dependency:

.package(url: "https://github.com/miquido/aegithalos.git", from: "2.0.0")

You can also use Xcode add SPM dependency option using this URL: https://github.com/miquido/aegithalos.git

Common usage

Main component of this library is Mutation struct. It is used to encapsulate and compose mutating functions. You can use it to define any kind of mutating function that can be passed around and applied on multiple subjects. For example - to prepare common style for UILabel applied on different screens in your application.

let labelSetup = Mutation { (label: UILabel) in
  label.textAlignment = .center
  label.textColor = .gray
}

You can use it to apply same setup whenever it is needed...

labelSetup.apply(on: myLabel)

... or even instantiate new subjects (conforming to EmptyInstantiable) with mutations applied.

let newLabelAfterSetup = labelSetup.instantiate()

Moreover mutations can be composed to refine and apply large sets of mutations on complex subjects.

let baseLabelSetup = Mutation { (label: UILabel) in
    /* do some base setup */
  }
let errorLabelSetup = Mutation
  .combined(
    baseLabelSetup,
    Mutation { (label: UILabel) in
      /* add setup for errors */
    }
  )

AegithalosCocoa

Aegithalos comes with set of usefull extensions for UIKit already prepared in AegithalosCocoa package. You can easily prapare any kind of UI setup with it, even layout constraints. Lets have a Signin with Apple button:

import AegithalosCocoa

let signinWithAppleButtonSetup = Mutation<UIButton>
  .combined(
    .backgroundColor(.black),
    .cornerRadius(5),
    .heightAnchor(.equalTo, 50),
    .titleColor(.white),
    .titleAlignment(.center),
    .titleFont(.systemFont(ofSize: 14, weight: .medium)),
    .title(localized: "com.miquido.signin.apple.button.tittle"),
    .titleInsets(UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 0)),
    .tintColor(.white),
    .image(symbol: "applelogo")
  )

License

Copyright 2020-2021 Miquido

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

GitHub

link
Stars: 9
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Fix overloads selection
2 years ago

Fixed selection of method overloads between reference and value types.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics