How to retrieve more than 1000 rows from Parse.com?

前端 未结 10 1044
独厮守ぢ
独厮守ぢ 2020-11-29 19:54

I have been using Parse to retrieve a data for a list view. Unfortunately they limit requests to 100 by default to a 1000 max. I have well over that 1000 max in my class. I

10条回答
  •  我在风中等你
    2020-11-29 20:24

    GENERIC VERSION For SWIFT 4:

    Warning: this is not tested!

    An attempt to adapt nyxee's answer to be usable for any query:

    func getAllRecords(for query: PFQuery, then doThis: @escaping (_ objects: [PFObject]?, _ error: Error?)->Void) {
        let limit = 1000
        var objectArray : [PFObject] = []
        query.limit = limit
        func recursiveQuery(_ loopCount:  Int = 0){
            query.skip  = limit * loopCount
            query.findObjectsInBackground(block: { (objects, error) in
                if let objects = objects {
                    objectArray.append(contentsOf: objects)
                    if objects.count == limit {
                        recursiveQuery(loopCount + 1)
                    } else {
                        doThis(objectArray, error)
                    }
                } else {
                    doThis(objects, error)
                }
            })
        }
        recursiveQuery()
    }
    

提交回复
热议问题