Contents

p-x9/swift-object-association

A swift library for associating objects as properties with reference type objects.

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)

Package Metadata

Repository: p-x9/swift-object-association

Default branch: main

README: README.md