IT STARTS WITH A PAGED REQUEST I’ll spare you the details. The most important thing is this: struct Cursor { let page: Int let perPage: Int let parameters: [String: Any]? }
LET’S MOVE TO THE STUFF THE DATA SOURCE • It uses generics to handle photos and collections • It uses a factory to generate cursors and requests protocol PagedDataSourceFactory { func initialCursor() -> Cursor func request(with cursor: Cursor) -> PagedRequest }
SO WHAT ABOUT THE FACTORY? THAT’S WHERE IT GETS REALLY enum PhotosDataSourceFactory: PagedDataSourceFactory { case photos(order: GetPhotosRequest.Order) case trending case search(query: String) case collection(identifier: String, curated: Bool) }
OK, BUT HOW TO USE THIS? The PhotosViewController uses a data source: var dataSource: PagedDataSource Which is set as easily as this: photosViewController.dataSource = PhotosDataSourceFactory.search(query:”summer").dataSource