Swift library inspired by Kotlin scope functions
Scoped
already conforms to NSObject
and some other types. You can find them here
let imageView = UIImageView().also {
$0.image = UIImage(systemName: "iphone")
$0.contentMode = .scaleAspectFill
}
To use Scoped
with your type you need to make an extension
extension Person: Scoped {}
let adam = Person("adam").apply {
$0.age = 32
$0.city = "London"
}
You can also just use with
function with any type
let anyType = with(AnyType()) {
$0.value = "value"
}
- Select File menu > Add Packages...
- Enter "https://github.com/DezorkIT/Scoped" into the package repository URL text field