终止未捕获的异常 - Swift 2 Parse

时间:2015-09-22 07:02:42

标签: ios swift parse-platform swift2

我正在使用Parse作为我的数据库,我刚刚使用swift 2将解析SDK和Xcode更新到版本7.但是,现在我在下面的查询开始时收到错误。问题始于“findobjectsinbackground”部分,因为没有看到“第三”打印。有什么想法吗?

错误:

  

2015-09-22 09:57:45.247 MyProject [456:133409] *终止app到期   未捕获的异常'NSInternalInconsistencyException',原因:   '此查询具有出色的网络连接。你得等一等   直到它完成。   * 第一次抛出调用堆栈:(0x275d386b 0x38f86dff 0x275d37b1 0x638ac9 0x638b41 0x639bf9 0x6397bb 0x6399bf 0x2b5e78 0x2b4e94 0x2b5154   0x2b6e56ab 0x2b79fe97 0x2b79fd91 0x2b79f135 0x2b79ed8f 0x2b79e9dd   0x2b79e957 0x2b6e16bb 0x2afad67d 0x2afa8d79 0x2afa8c09 0x2afa8129   0x2afa7deb 0x2b6d860d 0x275960f1 0x275943e7 0x27594825 0x274e71e9   0x274e6fdd 0x3078baf9 0x2b74c18d 0x5fa6f4 0x396b1873)libc ++ abi.dylib:   以NSException类型的未捕获异常终止

        followArray.removeAll(keepCapacity: false)
    followArray2.removeAll(keepCapacity: false)


        let followQuery = PFQuery(className: "follow")
        followQuery.whereKey("user", equalTo: PFUser.currentUser()!.username!)
        followQuery.whereKey("followAproval", equalTo: 1)
        followQuery.addDescendingOrder("createdAt")

        var myObjects = [PFObject]()

        followQuery.findObjectsInBackgroundWithBlock {
        (objects:[PFObject]?, error:NSError?) -> Void in

        if error == nil {

        myObjects = objects!

            for object in myObjects {

                self.followArray.append(object.objectForKey("userToFollow") as! String)

            }

         }
        }


        var myObjects2 = [PFObject]()

        let generalQuery = PFQuery(className: "tweets")
        generalQuery.addDescendingOrder("createdAt")
        generalQuery.limit = 100

        followQuery.findObjectsInBackgroundWithBlock {
        (objects:[PFObject]?, error:NSError?) -> Void in

        if error == nil {

            myObjects2 = objects!

        for object in myObjects2 {

            self.followArray2.append(object.objectForKey("userName") as! String)

             }
          }
        }

1 个答案:

答案 0 :(得分:0)

我认为,由于您的任务是异步的,objects实际上可以随着您的迭代而改变。我建议你先把它解决为一个变量。从你的代码:

print("second")

var myObjects = PFObject()

followQuery.findObjectsInBackgroundWithBlock {
    (objects:[PFObject]?, error:NSError?) -> Void in

    print("third")

    if error == nil {
        myObjects = objects 
    }
}

for object in myObjects! {

    self.followArray.append(object.objectForKey("userToFollow") as! String)

}