A convenience Swift extension and initial
- iOS 11.0+
- Xcode 10.0+
- Swift 5.0+
OhSwifter available through Cocoapods, simply add the following line to your Podfile:
pod 'OhSwifter'
private let label: UILabel = {
let label = UILabel()
label.font = UIFont.systemFont(ofSize: 14, weight: .medium)
label.textColor = .gray
label.textAlignment = .left
label.text = "Label Wording"
label.numberOfLines = 0
return label
}()- Type
labelseven times. 😱 let lable = UILabel()andreturn labellooks a bit redundant.
It too much and too long to me.
private let ohLabel = UILabel().oh
.style(font: UIFont.systemFont(ofSize: 12, weight: .medium), color: .gray)
.textAlignment(.left)
.text("Label Wording")
.numberOfLines(0)
.done()- First, less to define property type. Ex:
label: UILabel. - Second, use
ohwrapper for namespacing, can distinguish origin function or property, and less smart reminder type.
Note:
.dnoe()is must. Although I think this is a bit redundant, But there is no better idea at the moment.
private let button: UIButton = {
let button = UIButton()
button.setTitle("Button Wording", for: .normal)
button.setTitleColor(.black, for: .normal)
button.setTitleColor(.gray, for: .highlighted)
button.layer.cornerRadius = 12
button.layer.borderColor = UIColor.darkGray.cgColor
button.layer.borderWidth = 1
return button
}()- Type
buttoneight times. 😱 let button = UIButton()andreturn buttonredundant like UILabel.- type
.layertwice.
private let ohButton = UIButton().oh
.title("Button Wording", for: .normal)
.titleColor(.black, for: .normal)
.titleColor(.gray, for: .normal)
.cornerRadius(12)
.border(color: .darkGray, width: 1)
.done()- Need not to type any
button. - Need not to type any layer
- Border color and width mergi to on function to call
If you don't find style setting on initialized after oh, open an issue. or yout can use createConfigurator.
like this:
.createConfigurator { (button) in
// ...
}OhSwifter is released under the MIT license. See LICENSE for details.