Search code examples
iosproperty-observer

How to set a property observer on system variable


I have the following variable: private var screenWidth = UIScreen.mainScreen().bounds.width

I was wondering how I could set a property observer on it? Or get the latest version of it when it updates?


Solution

  • There's no general approach that works for everything. You can often use Key-Value Observing. In this case, you can listen for the UIScreenModeDidChangeNotification notification.