Silver challenge Ch 20

Alright, so I hacked the following together. I didn’t want to add a button to select whether an interesting photo was desired or a recent one, so I used a random number generator instead. I hope I didn’t forget anything!

Modify (and rename) PhotoStore’s fetchInterestingPhotos:

func fetchPhotosList(completion: @escaping (PhotosResult) -> Void) {
    
    var url: URL
    
    // Add random number generator to select either an interesting or recent photo
    let random = Int(arc4random_uniform(2))
    switch random {
    case 0:
        url = FlickrAPI.interestingPhotosURL
    default:
        url = FlickrAPI.recentPhotosURL
    }

Change viewDidLoad in PhotosViewController to use this new name:

override func viewDidLoad() {
    super.viewDidLoad()
    
    store.fetchPhotosList {
        (photosResult) -> Void in 

Also add a new case to the enum in FlickrAPI:

// Added recentPhotos
enum Method: String {
    case interestingPhotos = "flickr.interestingness.getList"
    case recentPhotos = "flickr.photos.getRecent"
}

Also in FlickrAPI, add the following method:

// Add for recent photos
    static var recentPhotosURL: URL {
        return flickrURL(method: .recentPhotos, parameters: ["extras": "url_h, date_taken"])
    }

Please let me know your feedback, thanks!

I’d rather use UITabBarController to switch between the two :slight_smile:

1 Like

I used a swipe up and down in the PhotosViewController to shuttle between the two.

A UISegmentedControl would suffice.