Latest 0.1.2
License MIT
Platforms ios 10.0


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


  • Associated objects stay alive unless internal clean-up is performed, although
    this does happen automatically whenever the 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.
  • No attempt whatsoever to make it thread safe yet,
    recommend only using from main thread for now.


Import the framework:

import AssociatedObjects

Any 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

Latest podspec

    "name": "SwiftAssociatedObjects",
    "module_name": "AssociatedObjects",
    "version": "0.1.2",
    "summary": "Associated objects (and values) in pure Swift 3",
    "description": "Allows associating an object or value onto any object instance using a key.nAssociations are maintained for the lifetime of the object that owns them.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": "Jay Abbott",
    "platforms": {
        "ios": "10.0"
    "source": {
        "git": "",
        "tag": "0.1.2"
    "source_files": "AssociatedObjects"

Pin It on Pinterest

Share This