有没有办法让解析查询同步?我尝试将查询更改为findObjects而不是findObjectsInBackgroundWithBlock。我似乎无法弄清楚它的语法。有人可以帮我解决这个问题吗?任何帮助表示赞赏。感谢。
var messageQuery = PFQuery(className: "Message")
messageQuery.whereKey("GUID", equalTo: GUID)
messageQuery.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
// The find succeeded.
println("Successfully retrieved \(objects.count) scores.")
// Do something with the found objects
if let objects = objects as? [PFObject] {
for object in objects {
println("in loop of objects retrieved")
object.delete()
}
}
messages.removeAtIndex(messageIndex)
//objectIDArr.removeAtIndex(messageIndex)
}else {
// Log details of the failure
println("Error: \(error) \(error.userInfo!)")
}
}
答案 0 :(得分:3)
您可以调用findObjects
方法,该方法返回NSArray。
See the reference on parse
e.g:
PFQuery query = PFQuery(classname: "Message")
query.whereKey("GUID", equalTo: GUID)
NSArray messages = query.findObjects()
for message in messages {
//do whatever you want with your message object
}