NSObject already has been compatible with DuctTape, so you can access .ductTape property like below.
let builder: Builder<UIView> = UIView().ductTape
If you access .ductTape, it returns Builder that provides setter of properties via KeyPath dynamicMemberLookup.
let view: UIView = UIView().ductTape
.backgroundColor(.red)
.translatesAutoresizingMaskIntoConstraints(false)
How to access methods
If you want to access methods of object which is building, func reinforce(_ handler: (Base) -> Void) Builder<Base> enable to access methods.
let collectionView: UICollectionView = UICollectionView().ductTape
.backgroundColor(.red)
.reinforce { collectionView in
collectionView.register(UITableViewCell.self, forCellWithReuseIdentifier: "Cell")
}
Builder has func reinforce<T1, ...>(_ t1: T1, ..., handler: (Base) -> Void) Builder<Base> methods.
In additional usage, be able to access outside object with func reinforce if passing objects as arguments.
DuctTape
📦 KeyPath dynamicMemberLookup based syntax sugar for Swift.
Above is same as below definition.
Usage
NSObject already has been compatible with DuctTape, so you can access
.ductTape
property like below.If you access
.ductTape
, it returnsBuilder
that provides setter of properties via KeyPath dynamicMemberLookup.How to access methods
If you want to access methods of object which is building,
func reinforce(_ handler: (Base) -> Void) Builder<Base>
enable to access methods.Builder
hasfunc reinforce<T1, ...>(_ t1: T1, ..., handler: (Base) -> Void) Builder<Base>
methods. In additional usage, be able to access outside object withfunc reinforce
if passing objects as arguments.How to use DuctTape with self-implemented classes
There are two ways to use DuctTape.
Sample Code
Requirement
Installation
CocoaPods
DuctTape is available through CocoaPods. To install it, simply add the following line to your
Podfile
:Carthage
If you’re using Carthage, simply add DuctTape to your
Cartfile
:Swift Package Manager
Simply add the following line to your
Package.swift
:License
DuctTape is released under the MIT License.