5
[AsyncRequest performGetRequestWithUrl:[NSString stringWithFormat:@"http://%@/api/streams/%d", @"server.herokuapp.com", userId]
completionHandler:^(NSDictionary *result, NSError *error) {
// Create new SBJSON parser object
NSError *e;
NSArray *jsonArray =[NSJSONSerialization JSONObjectWithData:result options:NSJSONReadingMutableContainers error: &e];
NSLog(@"parse result to JSON object with jsonArray: %@ and error: %@", jsonArray, e.description);
if ([jsonArray valueForKey:@"error"]) {
return nil;
}
NSLog(@"getStreams size of the return array: %d", [jsonArray count]);
NSMutableArray* data = [[NSMutableArray alloc] initWithCapacity:0];
if (jsonArray) {
data = [[NSMutableArray alloc] initWithCapacity:[jsonArray count]];
for (NSDictionary *item in jsonArray) {
NSLog(@"item: %@", item);
[data addObject:[[Stream alloc] initWithJSONObject:item]];
}
}
onComplete(data, error);
}];
我收到這個代碼奇怪的錯誤。它顯示錯誤消息「獲取不兼容的塊指針類型發送void *(^)(NSDictionary * _strong,NSError * _strong)到參數的類型'void(^)(NSDictionary * _strong,NSError * _strong)'獲取不兼容的塊指針類型發送無效*(^)
Here是函數簽名:
+(void)performGetRequestWithUrl:(NSString *)requestUrl completionHandler:(void (^)(NSDictionary *result, NSError *error))completionBlock
謝謝太糟糕了,在Xcode中的錯誤信息是混亂的 – flashsnake
@flashsnake錯誤消息是說,你正在傳遞。一個將'void *'返回給參數的塊,該參數需要一個返回void的塊。在C和Objective-C中,void *是任意指針的類型; nil'實際上被定義爲void *(0)',所以當你輸入'return nil'時,編譯器推斷你的返回類型爲'void *'。而如果你在'return'語句之後沒有任何東西,或者沒有'return',它會按照參數的預期推斷返回類型'void'。 –