Can't seem to limit and offset a pastebin URL

can’t seem to limit and offset a pastebin URL what should I be looking into to resolve this?

want to load n items, and load more from the API when the user reaches the end of the collection view (via scrollViewDidScroll /willDisplay); below is my interactor:

at this point, thinking of just splitting the json data into chunks before parsing :confused:

import UIKit
import SwiftyJSON

class PhotoInteractor: NSObject {
    func fetchPhotos(completionHandler: @escaping (([Photo], Error?) -> Void)) {
        let url = URL(staticString: "https://pastebin.com/raw/wgkJgazE")
        URLSession.shared.dataTask(with: url) { (data, response, error) in
            if let error = error {
                completionHandler([], error)
                return
            }

            if let data = data {
                if let jsonData: JSON = try? JSON(data: data) {
                    completionHandler(Photo.parsePhotos(data: jsonData), nil)
                }
            }
        }.resume()
    }
}

@lganti Thanks very much for your question!

Take a look at the following tutorial. This I believe answers your question :slight_smile:

I hope this helps!

All the best.

Hi @Iganti,
Infinite scrolling is a tricky one. BTW, a recent article that I read suggests that it is time up for infinite scrolling. In fact the exact title of that article is “It’s time to kill the infinte scroll”

Anyways, instead of breaking up the json into chunks, you can d/l it in one call and instantiate the proper structures, etc. Now when you try to download the data for the rows that is what you would queue for infinite scrolling, where you would download the images for the next N rows.

cheers,

This topic was automatically closed after 166 days. New replies are no longer allowed.