O'Reilly logo

Swift by Example by Giordano Scalzo

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

Downloading the background image

Before moving on to download the actual forecast, we'll introduce the topic of networking downloading a geolocalized background image.

Searching in Flickr

To get an image, we'll use the API of Flickr, a famous image-hosting website. First of all, we override the viewWillAppear function in PrettyWeatherApp so that a new image will be downloaded every time the ViewController appears:

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        
        let lat:Double = 48.8567
        let lon:Double = 2.3508
        
        FlickrDatastore().retrieveImageAtLat(lat, lon: lon){ image in
            self.render(image)
        }
    }

To implement the searching feature, we set a dummy value using the coordinates of Paris. Then, we create a new file named FlickrDatastore ...

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