gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 14:03:23 27 4
gpt4 key购买 nike

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

错误:

2015-09-22 09:57:45.247 MyProject[456:133409] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'This query has an outstanding network connection. You have to wait until it's done.' * First throw call stack: (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: terminating with uncaught exception of type 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)

}
}
}

最佳答案

我认为由于您的任务是异步的,因此当您迭代它时,对象实际上可能会发生变化。我建议你首先将其解析为变量。从您的代码:

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)

}

关于ios - 因未捕获的异常而终止 - Swift 2 Parse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32710391/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com