Created
August 16, 2017 02:13
-
-
Save hechen/4be658423d914e6a7c928f0411052d74 to your computer and use it in GitHub Desktop.
AssociatedObject of swift version
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
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