2015-05-27 29 views
0

我使用解析1.7.4,這爲y的代碼:目標C不相容的嵌段指針類型發送

+(NSArray *)getCategorieFromParse{ 



    PFQuery *categoriesQuery = [PFQuery queryWithClassName:@"Categorie"]; 

    [categoriesQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){ 

     if (!error) 

      return objects; 

     else 

      return [[NSArray alloc] init]; 

    }]; 




} 

但是這是產生這樣的錯誤:

不相容的嵌段指針類型'發送的NSArray *(^)(NSArray的 * __強,NSError * __強)」到類型的參數 'PFArrayResultBlock __nullable'(又名 '空隙(^)(的NSArray * __nullable __strong,NSError * __nullable __strong)')

在返回線

+0

差不多重複這裏。不同的框架,同樣的問題。 http://stackoverflow.com/q/29500188/620197 –

回答

3

你的塊沒有用返回類型聲明,並且它返回一個NSArray *,它是返回一個NSArray *的塊。你正在調用的方法需要一個返回void的塊。顯然你的區塊是不可接受的。

我懷疑這個區塊應該做什麼有一些深刻的誤解。您的方法getCategorieFromParse 不能返回一個數組。它發送一個異步請求,並且您的回調塊將在getCategorieFromParse返回後被調用很長時間。回調塊不應該嘗試返回任何東西;它的工作是處理它給出的數組。

2

您無法從代碼塊中返回值。您應該使用delegate(僅在Google上找到的示例)。

0

您進行異步調用。你不能同步返回數組。

解決方案:讓你的方法也是異步:

+(void) getCategorieFromParse:(void (^)(NSArray*))completion 
{ 
    PFQuery *categoriesQuery = [PFQuery queryWithClassName:@"Categorie"]; 

    [categoriesQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){ 

     if (!error) 

      completion(objects); 

     else 

      completion([[NSArray alloc] init]); 

    }]; 
} 
相關問題