O'Reilly logo

Building Apple Watch Projects by Stuart Grimshaw

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Interface Controllers

Now the SessionManager class is ready to test. To do this, we simply need to create the sharedInstance in the InterfaceController class which we will now implement.

In the project navigator, select InterfaceController.swift, and add the following code to the InterfaceController class's awakeWithContext method:

    override func awakeWithContext(context: AnyObject?) {
        super.awakeWithContext(context)
        requestWeatherData()
    }

The compiler will complain about not knowing any such method, so we'll fix that now.

Add the following function to the InterfaceController class:

 func requestWeatherData() { //1 WeatherSessionManager.sharedInstance.fetchWeatherData() { //2 (data: NSData?, response: NSURLResponse?, taskError: NSError?) -> Void in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required