Skip to main content
 首页 » 操作系统

xcode之如何使解析查询同步快速

2024年01月01日60softidea

有什么方法可以使解析查询同步吗?我尝试将查询更改为 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!)") 
 
        } 
 
    } 

请您参考如下方法:

您可以调用 findObjects 方法,它返回一个 NSArray。 See the reference on parse

例如:

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 
}