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

标签 xcode swift asynchronous parse-platform synchronous

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

关于xcode - 如何使解析查询同步快速,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29360566/

相关文章:

objective-c - 用Delphi XE2制作的.dylib不能被Xcode应用程序使用

ios - 无法将UITextField聚焦在嵌套的UIView中

ios - 如何在 iPhone Xs 模拟器上启用 Siri 的文本输入?

ios - <未知> :0: error: no such file or directory: 'COCOAPODS'

ios - iOS团队开发中如何管理共享资源?

swift - 在 swift 中执行 while == nil 最惯用的方法是什么?

arrays - 希望将 EMV 数据解析为 TLV

node.js - Node.js 异步函数的可读性

.net - 在 silverlight 上异步调用同步 WCF 操作协定方法

javascript - 解决数组推送的 promise - javascript