Modeling the Photo

Next, you will create a Photo class to represent each photo that is returned from the web service request. The relevant pieces of information that you will need for this application are the id, the title, the url_z, and the datetaken.

Create a new Swift file called Photo and declare the Photo class with properties for the photoID, the title, and the remoteURL. Finally, add a designated initializer that sets up the instance.

Listing 20.16  Creating the Photo class (Photo.swift)

import Foundation

class Photo {
    let title: String
    let remoteURL: URL
    let photoID: String
    let dateTaken: Date
}

You will use this class shortly, once you are parsing the JSON data.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset