ObjectAssociation

0.5.0

🔗 A swift library for associating objects as properties with reference type objects.
p-x9/swift-object-association

What's New

v0.5.0

2024-01-31T11:29:59Z

What's Changed

  • Fix for SWIFT_ASSOCIATION_ASSIGN policy by @p-x9 in #8
  • weak association policy by @p-x9 in #9
  • version 0.5.0 by @p-x9 in #10

Full Changelog: 0.4.0...0.5.0

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)

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sat Oct 19 2024 21:08:22 GMT-0900 (Hawaii-Aleutian Daylight Time)