Created
August 27, 2018 08:05
-
-
Save lamprosg/e9415a81ce79ef7d6bf1a9a3971ee2c9 to your computer and use it in GitHub Desktop.
(iOS) Extensions with computed properties
This file contains hidden or 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 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