Skip to content

Instantly share code, notes, and snippets.

@lamprosg
Created August 27, 2018 08:05
Show Gist options
  • Select an option

  • Save lamprosg/e9415a81ce79ef7d6bf1a9a3971ee2c9 to your computer and use it in GitHub Desktop.

Select an option

Save lamprosg/e9415a81ce79ef7d6bf1a9a3971ee2c9 to your computer and use it in GitHub Desktop.
(iOS) Extensions with computed properties
extension UIViewController {
private static var _myComputedProperty = [String:Bool]()
var myComputedProperty:Bool {
get {
let tmpAddress = String(format: "%p", unsafeBitCast(self, to: Int.self))
return UIViewController._myComputedProperty[tmpAddress] ?? false
}
set(newValue) {
let tmpAddress = String(format: "%p", unsafeBitCast(self, to: Int.self))
UIViewController._myComputedProperty[tmpAddress] = newValue
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment