A swift library for associating objects as properties with reference type objects.
It works in the same way as objc_getAssociatedObject
/objc_setAssociatedObject
.
However, this library can also be used on Linux platforms and other platforms that do not run the Objective-C runtime.
Basically the same usage as objc_getAssociatedObject
/objc_setAssociatedObject
.
But there is no policy setting.
class ClassItem {
enum Keys {
static var value: UInt8 = 0
}
var value: String? {
get {
getAssociatedObject(
self,
&ClassItem.Keys.value
) as? String
}
set {
setAssociatedObject(
self,
&ClassItem.Keys.value,
newValue
)
}
}
}
removeAssociatedObjects(self)