findObjectsInBackgroundWithBlock块签名不正确 [英] findObjectsInBackgroundWithBlock block signature not correct

查看:70
本文介绍了findObjectsInBackgroundWithBlock块签名不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此代码获取一堆行

I'm trying to fetch a bunch of rows with this code

var query = PFQuery(className:"Test")
query.findObjectsInBackgroundWithBlock {
    (objects: NSArray?, error: NSError?) in

    // do something
}

但是它无法编译,我收到以下错误:

But it doesn't compile, I get the following error:

无法使用类型为(((NSArray ?, NSError?)-> _)''

Cannot invoke 'findObjectsInBackgroundWithBlock' with an argument list of type '((NSArray?, NSError?) -> _)'

文档我找到了:

块:要执行的块.它应该具有以下参数签名:
^(NSArray * objects,NSError * error)

block: The block to execute. It should have the following argument signature:
^(NSArray *objects, NSError *error)

似乎与我非常相似.我在做什么错了?

Which seems to be pretty similar to me. What am I doing wrong?

推荐答案

另一篇帖子中找到了正确的语法.参数列表或包装/展开对象都没有问题;相反,必须将闭包作为参数传递给findObjectsInBackgroundWithBlock.像这样写时可以工作:

Found the correct syntax in another post. Nothing wrong with the arguments list or wrapping/unwrapping the objects; instead, the closure had to be passed as an argument to findObjectsInBackgroundWithBlock. It works when written like this:

query.findObjectsInBackgroundWithBlock( { (NSArray results, NSError error) in
    // do something
})

这篇关于findObjectsInBackgroundWithBlock块签名不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆