Skip to content

Instantly share code, notes, and snippets.

@mike3k
Created July 3, 2018 22:31
Show Gist options
  • Save mike3k/672d437a5eec448e2f06d723ade83e14 to your computer and use it in GitHub Desktop.
Save mike3k/672d437a5eec448e2f06d723ade83e14 to your computer and use it in GitHub Desktop.
least ugly way to add a property to a class extension
private var fooKey = 0
extension UIViewController {
var foo: Bool {
set {
objc_setAssociatedObject(self, &fooKey, NSNumber(value: newValue), .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
get {
return objc_getAssociatedObject(self, &fooKey) as? Bool ?? false
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment