2015-10-26 70 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時,錯誤將會奇蹟般消失! –