取出>来自Parse类的1000个条目

时间:2015-02-03 00:46:48

标签: swift parse-platform

我试图从包含2500个条目的类中获取信息。当我尝试仅1000个条目时,此代码有效。

但是,当我把它放在for循环中时,它会抛出以下错误:' NSInternalInconsistencyException',原因:'此查询具有出色的网络连接。你必须等到它完成。'

以下是代码:

func loadDataFromParse(){
    var classLimit = 2
    println("Loading Parse data")
    var query = PFQuery(className: "StopList")
    query.limit = 1000

    for (var j = 0; j < classLimit+1; j++)
    {
        query.skip = 1000*j

        query.findObjectsInBackgroundWithBlock ({(objects:[AnyObject]!, error: NSError!) in
            if(error == nil){
                if let stopObjects = objects as? [PFObject] {
                    for stop in stopObjects {
                        // Code goes here
                    }
                }}
            else{
                println("Error in retrieving \(error)")
            }

        })

    }


}

关于发生了什么的任何想法?

1 个答案:

答案 0 :(得分:3)

想出来!每次循环迭代时都需要重新初始化查询变量:

func loadDataFromParse(){
    var i = 1
    var limit = 2
    println("Loading Parse data")

    for (var j = 0; j < limit+1; j++)
    {
        var query = PFQuery(className: "StopList")
        query.limit = 1000
        query.skip = 1000*j
        query.findObjectsInBackgroundWithBlock ({(objects:[AnyObject]!, error: NSError!) in
            if(error == nil){
                if let stopObjects = objects as? [PFObject] {
                    for stop in stopObjects {
                        println(i)
                        i += 1
                    }
                }}
            else{
                println("Error in retrieving \(error)")
            }       
        })     
    }
}