Last active
January 26, 2018 03:29
-
-
Save hisoka0917/d9c507c0dc94b7cc01ef62431bf57a81 to your computer and use it in GitHub Desktop.
Extension property in Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSObject { | |
private struct AssociatedKeys { | |
static var extensionProps: UInt8 = 0 | |
} | |
private var extensionProps: NSObject? { | |
get { | |
return objc_getAssociatedObject(self, &AssociatedKeys.extensionProps) as? NSObject | |
} | |
set { | |
objc_setAssociatedObject(self, &AssociatedKeys.extensionProps, 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