【问题标题】:What am I doing wrong with this method definition and call?这个方法定义和调用我做错了什么?
【发布时间】:2013-06-12 17:48:25
【问题描述】:

我的班级标题中有这个:

typedef void(^DBSuccessBlock)();
typedef void(^DBErrorBlock)(int errorNumber, NSString* description);

- (void) connect:(NSString*) path isFile:(BOOL) flag
        success:(DBSuccessBlock) success
          error:(DBErrorBlock) error;

这就是我尝试调用该方法的方式:

[db connect:filePathName isFile:YES success:^{
    // initialize db here if necessary
} error:^(int errorNumber, NSString *description) { //error on this line
    NSLog(description);
    return nil;
}];

错误行给了我这个编译错误:不兼容的块指针类型将'void *(^)(int, NSString *_strong)'发送到'DBErrorBlock'类型的参数(又名'void (^) (int, NSString *_strong)')

我看到的唯一区别是 void* 与 void,我不知道为什么。谁能帮我弄清楚为什么我会收到这个错误?谢谢。

【问题讨论】:

  • 你 100% 确定这是你的 typedefs 和方法声明的样子吗?
  • 我直接从我的文件中复制了它。

标签: objective-c-blocks


【解决方案1】:

您正在返回类型为void 的块中返回值nil。删除return nil 行。

【讨论】:

  • 就是这样。谢谢。仍在学习使用块的细微差别。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-17
  • 1970-01-01
  • 1970-01-01
  • 2020-12-12
  • 2013-02-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多