CocoaPods trunk is moving to be read-only. Read more on the blog, there are 12 months to go.
| TestsTested | ✗ |
| LangLanguage | SwiftSwift |
| License | MIT |
| ReleasedLast Release | Sep 2016 |
| SPMSupports SPM | ✗ |
Maintained by Jay Abbott.
Works, but experimental.
Associate objects and values with any instance of any class. The associated objects/values automatically go away after the instance is deinited (but see issues below).
Issues:
associate(value:withKey:) and associatedValue(forKey:) methods are called. So as long as the interface is being used regularly (on any instance), it’s ok.Import the framework:
import AssociatedObjectsAny classes you want to use this feature on need to be made Associable:
extension SomeClass: Associable {}Then just call the methods defined in the Associable protocol:
someClassInstance.associate(value: 7, withKey: "anInt")
someClassInstance.associate(value: anyObjectInstance, withKey: "anObject")
// Later...
let theInt = someClassInstance.associatedValue(forKey: "anInt") as? Int
let theObject = someClassInstance.associatedValue(forKey: "anObject") as? AnyObject