0

i have one bool variable isValidSession i want to observer this variable in whole application whenever it becomes false it will automatically call method and renew the session.

override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {

        if let newValue = change?[NSKeyValueChangeNewKey] {

        }
    }
Janak Thakkar
  • 414
  • 5
  • 20
  • [Property Observers](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Properties.html#//apple_ref/doc/uid/TP40014097-CH14-ID254) should be can full-fill your scenario. – DavidODW Feb 23 '16 at 14:10

1 Answers1

0

Try this:

var isValidSession: Bool = true {
        didSet {
            if isValidSession == false  {
                //do something (renew session here)
            }
        }
    }
bcamur
  • 894
  • 5
  • 10