An open API service indexing awesome lists of open source software.

https://github.com/miquido/aegithalos

Function composition for functional scared. The project was made by Miquido. https://www.miquido.com/
https://github.com/miquido/aegithalos

function-composition styling swift uikit

Last synced: 6 months ago
JSON representation

Function composition for functional scared. The project was made by Miquido. https://www.miquido.com/

Awesome Lists containing this project

README

          









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:

```swift
.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.

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

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

```swift
labelSetup.apply(on: myLabel)
```

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

```swift
let newLabelAfterSetup = labelSetup.instantiate()
```

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

```swift
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:

```swift
import AegithalosCocoa

let signinWithAppleButtonSetup = Mutation
.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.