Apress Beginning iPhone Development with Swift, Exploring the iOS SDK (2014) by Kim Topley & Fredrik Olsson & Jeff LaMarche

Apress Beginning iPhone Development with Swift, Exploring the iOS SDK (2014) by Kim Topley & Fredrik Olsson & Jeff LaMarche

Author:Kim Topley & Fredrik Olsson & Jeff LaMarche
Format: epub


let app = UIApplication.sharedApplication()

NSNotificationCenter.defaultCenter().addObserver(self,

selector: "applicationWillEnterForeground:",

name: UIApplicationWillEnterForegroundNotification,

object: app)

}

We start by getting a reference to our application instance, and then use that to subscribe to the UIApplicationWillEnterForegroundNotification, using the default NSNotificationCenter instance and a method called addObserver(_, selector:, name:, object:). We then pass the following to this method:

For the observer, we pass self, which means that our controller class (each of them individually, since this code is going into both of them) is the object that needs to be notified.

For selector, we pass a selector to the applicationWillEnterForeground() method we just wrote, telling the notification center to call that method when the notification is posted.

The third parameter, UIApplicationWillEnterForegroundNotification, is the name of the notification that we’re interested in receiving.

The final parameter, app, is the object from which we’re interested in getting the notification. We use a reference to our own application for this. If we passed nil for the final parameter instead, we would get notified any time any application posted the UIApplicationWillEnterForegroundNotification.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.