ChainSwift
is an extension that provides chainable way of setting properties in swift.
You can do this:
let titleLabel = UILabel().set
.text("Welcome")
.font(.systemFont(ofSize: 20))
.textAlignment(.center)
.get
Instead of this:
let titleLabel = UILabel()
titleLabel.text = "Welcome"
titleLabel.font = .systemFont(ofSize: 20)
titleLabel.textAlignment = .center
After installing add these lines to anywhere in your code:
import Foundation
import ChainSwift
extension NSObject: Chainable { } /// covers anything inheriting NSObject like UIView
Consider following class
class MyClass {
var text = ""
var int = 0
var myEnum: MyEnum = .value1
}
After adding this single line:
extension MyClass: Chainable { }
You will be able to do:
let myClass = MyClass()
myClass.set
.text("It works")
.int(99)
.myEnum(.value2)
print(myClass.text) // "It works"
print(myClass.int) // 99
print(myClass.myEnum) // .value2
/// immediate usage
let myClass = MyClass().set
.text("It works")
.int(99)
.myEnum(.value2)
.get // gains the instance back
It combines Swift's Key Path Member Lookup and func callAsFunction
features to achive this.
- LayoutSwift - Yet another Swift Autolayout DSL for iOS.
- SwiftUIRouter - An experimental navigation router for SwiftUI.
Note: Instructions below are for using SwiftPM without the Xcode UI. It's the easiest to go to your Project Settings -> Swift Packages and add ChainSwift from there.
To integrate using Apple's Swift Package Manager , without Xcode integration, add the following as a dependency to your Package.swift
:
dependencies: [
.package(url: "https://github.com/OrkhanAlikhanov/ChainSwift.git", .upToNextMajor(from: "1.0.1"))
]
and then specify "ChainSwift"
as a dependency of the Target in which you wish to use ChainSwift.
Just drag and drop the files in the Sources folder.
- Orkhan Alikhanov - Initial work - OrkhanAlikhanov
See also the list of contributors who participated in this project.
Hit the star π button! It helps! β€οΈ
This project is licensed under the MIT License - see the LICENSE file for details