项目作者: miquido

项目描述 :
Function composition for functional scared.
高级语言: Swift
项目地址: git://github.com/miquido/Aegithalos.git
创建时间: 2020-07-10T13:35:58Z
项目社区:https://github.com/miquido/Aegithalos

开源协议:Apache License 2.0

下载










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:

  1. .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.

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

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

  1. labelSetup.apply(on: myLabel)

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

  1. let newLabelAfterSetup = labelSetup.instantiate()

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

  1. let baseLabelSetup = Mutation { (label: UILabel) in
  2. /* do some base setup */
  3. }
  4. let errorLabelSetup = Mutation
  5. .combined(
  6. baseLabelSetup,
  7. Mutation { (label: UILabel) in
  8. /* add setup for errors */
  9. }
  10. )

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:

  1. import AegithalosCocoa
  2. let signinWithAppleButtonSetup = Mutation<UIButton>
  3. .combined(
  4. .backgroundColor(.black),
  5. .cornerRadius(5),
  6. .heightAnchor(.equalTo, 50),
  7. .titleColor(.white),
  8. .titleAlignment(.center),
  9. .titleFont(.systemFont(ofSize: 14, weight: .medium)),
  10. .title(localized: "com.miquido.signin.apple.button.tittle"),
  11. .titleInsets(UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 0)),
  12. .tintColor(.white),
  13. .image(symbol: "applelogo")
  14. )

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.