2015-10-26 71 views
0

我有这样的方法:Objective-C的不兼容的模块类型错误

- (void)shareItems:(NSArray *)shareItems fromViewController:(UIViewController *)viewController anchorView:(UIView *)anchorView completion:(void (^)(NSString *activityType, BOOL, NSError *))completionHandler; 

enter image description here

我只是想实现它的XCode 7.0.1和我收到以下错误信息:

如果你不能看到,我试图执行:

[[VMSocialShareManager defaultManager] shareItems:shareItems fromViewController:self anchorView:shareCell completion:^(NSString *activityType, BOOL completed, NSError *error) { 
    ... 
}]; 

但得到的错误:

Incompatible block pointer types sending 'void (^)(NSString *__strong, BOOL, NSError *__strong)' to parameter of type 'void (^)(BOOL, NSString *__strong, NSError *__strong)' 

OK,当然,我会尽量翻转BOOLNSString即使这是没有意义的:

[[VMSocialShareManager defaultManager] shareItems:shareItems fromViewController:self anchorView:shareCell completion:^(BOOL completed, NSString *activityType, NSError *error) { 
    ... 
}]; 

但随后即给出了错误:

Incompatible block pointer types sending 'void (^)(BOOL, NSString *__strong, NSError *__strong)' to parameter of type 'void (^)(NSString *__strong, BOOL, NSError *__strong)' 
+0

但问题是:如何在VMSocialShareManager_中实际声明此方法? – matt

+0

另请参见,一如既往http://fuckingblocksyntax.com/ –

+0

@matt:问题的第一行是方法声明。 – Ramsel

回答

0

您的声明中没有其他两个项目的名称。它应该是:

- (void)shareItems:(NSArray *)shareItems 
fromViewController:(UIViewController *)viewController 
     anchorView:(UIView *)anchorView 
     completion:(void (^)(NSString *name, BOOL flag, NSError *error))completionHandler; 

你缺少flagerror参数名称。

编辑:为了表明参数的顺序真的没有关系,我在AppDelegate中创建了一个带有上述方法签名的测试项目,并在application:didFinishLaunchingWithOptions:中调用它。它按预期运行。我附上了示例项目here

+0

这并没有摆脱错误。 =/ – Ramsel

+0

您是否忘记在实际调用方法时更改参数顺序? –

0

所以,事实证明,我只需要把activityType在中间,在successerror之间。不知道为什么,但它现在编译:

- (void)shareItems:(NSArray *)shareItems fromViewController:(UIViewController *)viewController anchorView:(UIView *)anchorView completion:(void (^)(BOOL success, NSString *activityType, NSError *error))completionHandler; 
+0

什么?但这没有道理!我刚刚创建了一个活动类型作为第一个参数的新项目。完美的作品。我觉得其他的东西一定是错的!我在我的答案中附加了示例项目。 –

+0

@Flying_Banana它绝对看起来像某种错误。我多次清理了这个项目,以确保这不是问题。我认为这与此有关,改变顺序只是迫使XCode重新编译。 – Ramsel

+0

嗯,我想有时会出现不可重现的错误:/也许下一次更新Xcode时,错误将会奇迹般消失! –