Skip to content

p-x9/swift-object-association

Repository files navigation

ObjectAssociation

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.

Github issues Github forks Github stars Github top language

Usage

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
            )
        }
    }
}

Remove all associated values

removeAssociatedObjects(self)

About

๐Ÿ”— A swift library for associating objects as properties with reference type objects.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors