ZHocean123
11/21/2017 - 6:22 AM

Associated.swift

class MyClass {
}

private var key: Void?

extention MyClass {
  var title: String? {
    get {
      return objc_getAssociatedObject(self, &key) as? String
    }
    set {
      objc_setAssociatedObject(self, &key, newValue, .OBJC_ASSOCIATED_RETAIN_NONATOMIC)
    }
  }
}