Hi,
I try to avoid using inheritance for just adding functionality - for that I use
(and love) extensions.
This works great for functions - but I find the lack for stored properties
support limiting.
Here’s my use case:
I want to map every textfield in my view controller to a JSON field - so it
would be very helpful to add a string Key property to all of the UITextFields
in my app.
For now this is how I solve this issue (inside the extension):
struct customProperties {
static var key : String?
}
var key : String? {
get {
return objc_getAssociatedObject(self, &customProperties.key)
as? String
}
set (value){
objc_setAssociatedObject(self,&customProperties.key,value,.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
I would love to just add an actual variable to the extension without the need
to use Obj-C associated objects._______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution