我试图从一个包含2500个条目的类中获取信息。当我只尝试了1000个条目时,这个代码是有效的。
但是,当我将它放入for循环中时,它会引发以下错误:“nsInternalConsistenceyException”,原因:“此查询有一个未完成的网络连接。你得等到事情结束。”
代码如下:

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)")
            }

        })

    }


}

有什么想法吗?

最佳答案

明白了!每次循环迭代时需要重新初始化查询变量:

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)")
            }
        })
    }
}

10-08 12:26