Gaine
is a tiny and elegant Swift Framework for initialize value and object conveniently.By the way, this repo is inspire by Then.
There is comparison between Gaine way and Then way:
lazy var foo = UILabel().then {
$0.textAlignment = .center
$0.textColor = .black
$0.text = "Hello, World!"
}
lazy var foo = Gaine(UILabel()) {
$0.textAlignment = .center
$0.textColor = .black
$0.text = "Hello, World!"
}
class MyType {
var name: String?
}
/// we need to write this line to make custom type confirm `Then` protocol
extension MyType: Then {}
class Demo {
lazy var foo = MyType().then {
$0.name = "value"
}
}
class MyType {
var name: String?
}
/// we don't need to write any more code for custom type
class Demo {
lazy var foo = Gaine(MyType()) {
$0.name = "value"
}
}
class Demo {
/// we need to use another keyword `with`
lazy var foo = CGSize().with {
$0.width = 100
$0.height = 200
}
}
class Demo {
/// the way to initialize is same
lazy var foo = Gaine(CGSize()) {
$0.width = 100
$0.height = 200
}
}
All code for Gaine is just 5 lines.
To run the example project, clone the repo, and run pod install
from the Example directory first.
Gaine is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'Gaine'
Maru-zhang, maru-zhang@foxmail.com
Gaine is available under the MIT license. See the LICENSE file for more info.