Skip to content

Instantly share code, notes, and snippets.

@maximbilan
Created October 8, 2015 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maximbilan/60fec2fc18425c9aa66b to your computer and use it in GitHub Desktop.
Save maximbilan/60fec2fc18425c9aa66b to your computer and use it in GitHub Desktop.
private var propertyAssociationKey: UInt8 = 0
extension String {
weak var property: CustomClass! {
get {
return objc_getAssociatedObject(self, &propertyAssociationKey) as? CustomClass
}
set(newValue) {
objc_setAssociatedObject(self, &propertyAssociationKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment