Book Image

Swift by Example

By : Giordano Scalzo
Book Image

Swift by Example

By: Giordano Scalzo

Overview of this book

Table of Contents (15 chapters)

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:

import FlickrKit

class FlickrDatastore {
    private let OBJECTIVE_FLICKR_API_KEY = "CREATE_API_KEY"
    private let OBJECTIVE_FLICKR_API_SHARED_SECRET = "CREATE_SHARED_SECRET...