Skip to content

Instantly share code, notes, and snippets.

@hechen
Created August 16, 2017 02:13
Show Gist options
  • Save hechen/4be658423d914e6a7c928f0411052d74 to your computer and use it in GitHub Desktop.
Save hechen/4be658423d914e6a7c928f0411052d74 to your computer and use it in GitHub Desktop.
AssociatedObject of swift version
private struct AssociatedKeys {
static var <#name#> = "<#name#>"
}
var <#name#>: String? {
get {
return objc_getAssociatedObject(self, &AssociatedKeys.<#name#>) as? String
}
set {
if let newValue = newValue {
objc_setAssociatedObject(self, &AssociatedKeys.<#name#>, newValue as String?,
.OBJC_ASSOCIATION_RETAIN_NONATOMIC
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment