Appliable makes configuring objects easier and more convenient using closures.
Table of Contents
let button = UIButton().apply {
$0.isUserInteractionEnabled = false
}UserDefaults.standard.apply {
$0.set("Value 1", forKey: "Key 1")
$0.set("Value 2", forKey: "Key 2")
$0.set("Value 3", forKey: "Key 3")
}- iOS 15.0+
- macOS 12.0+
- watchOS 8.0+
- tvOS 15.0+
Appliable is available as a Swift Package.
.package(url: "https://github.com/pawello2222/Appliable.git", .upToNextMajor(from: "1.0.0"))let button = UIButton().apply {
$0.isUserInteractionEnabled = false
}let label = UILabel()
label.apply {
$0.isUserInteractionEnabled = false
}let calendar = Calendar(identifier: .gregorian).applying {
$0.timeZone = .init(identifier: "UTC")!
$0.locale = .init(identifier: "en_US_POSIX")
}var calendar = Calendar(identifier: .gregorian)
calendar.apply {
$0.timeZone = .init(identifier: "UTC")!
$0.locale = .init(identifier: "en_US_POSIX")
}UserDefaults.standard.apply {
$0.set("Value 1", forKey: "Key 1")
$0.set("Value 2", forKey: "Key 2")
$0.set("Value 3", forKey: "Key 3")
}var array = Array(repeating: Date(), count: 3)
array.applyEach {
$0.addTimeInterval(1000)
}let array1 = Array(repeating: Date(), count: 3)
let array2 = array1.applyingEach {
$0.addTimeInterval(1000)
}let label = UILabel()
let button = UIButton()
[label, button].applyEach {
$0.isUserInteractionEnabled = false
}
let components = [UILabel(), UIButton()].applyEach {
$0.isUserInteractionEnabled = false
}- Value types
ArrayCalendarDateDictionarySetURLURLRequest
- Reference types
JSONDecoderJSONEncoderPropertyListDecoderPropertyListEncoder
- All classes inheriting from
NSObject
extension Calendar: Appliable {} // value types
extension JSONDecoder: ObjectAppliable {} // reference typesstruct Item: Appliable {
var value: Int?
}
let item = Item().applying {
$0.value = 1
}Appliable is available under the MIT license. See the LICENSE file for more info.
