ios - 尝试在 Parse 中查询对象

标签 ios swift parse-platform pfquery pfuser

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

        if error == nil {
            if let objects = objects as? [PFObject] {
                for object in objects {
                    print("woot")
                }
            }

        } else {
            // Log details of the failure
            print("Error: \(error) \(error!.userInfo)")
        }
        dispatch_async(dispatch_get_main_queue()){
            //reload the table view

            query.cachePolicy = PFCachePolicy.NetworkElseCache
        }

    }

出于某种原因,该行:

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

给我错误:

Cannot convert value of type '([AnyObject]?, NSError?) -> void to expected argument type 'PFQueryArrayResultBlock?'

我不知道如何修复错误。

谢谢!

最佳答案

结果 block 应该如下所示:

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

    if error == nil {
        if let objects = objects as? [PFObject] {
            for object in objects {
                print("woot")
            }
        }

    } else {
        // Log details of the failure
        print("Error: \(error) \(error!.userInfo)")
    }
    dispatch_async(dispatch_get_main_queue()){
        //reload the table view

        query.cachePolicy = PFCachePolicy.NetworkElseCache
    }
}

参见 Parse docs关于查询。

关于ios - 尝试在 Parse 中查询对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33375814/

相关文章:

javascript - 如何在 Parse 中创建一对多关系?

每次启动/重新运行应用程序时,iOS 文件路径都会发生变化

ios - 当不在 UIViewController 中时,如何触发 segue 以显示特定 View ?

iphone - 扫描 NSMutableArray 以获取字符串的一部分

arrays - 将数组扩展转换为 SequenceType?

ios - 如何在 swift 3 中以编程方式选择 collectionView 中的单元格?

swift - 使用自定义解码器解码 Firestore 结构时获取 DocumentID

ios - 将解析数据与 coredata 同步,如何确定要删除哪些对象?

ios - CLLocationManager 最后一个已知位置

ios - Parse.com 因超出突发限制而拒绝服务