Iphone 获取不兼容的块指针类型发送void*(^)
我在这个代码上遇到了奇怪的错误。它显示错误消息“获取不兼容的块指针类型,将void*(^)(NSDictionary*\u strong,NSError*\u strong)发送到'void(^)(NSDictionary*\u strong,NSError*\u strong)类型的参数” 这是函数签名:Iphone 获取不兼容的块指针类型发送void*(^),iphone,ios5,objective-c-blocks,Iphone,Ios5,Objective C Blocks,我在这个代码上遇到了奇怪的错误。它显示错误消息“获取不兼容的块指针类型,将void*(^)(NSDictionary*\u strong,NSError*\u strong)发送到'void(^)(NSDictionary*\u strong,NSError*\u strong)类型的参数” 这是函数签名: [AsyncRequest performGetRequestWithUrl:[NSString stringWithFormat:@"http://%@/api/streams/%d",
[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);
}];
将“return nil”更改为“return”@flashsnake错误消息表示您正在将返回
void*
的块传递给期望块返回void
的参数。在C和Objective-C中,void*
是任意指针的类型;nil
实际上定义为void*(0)
因此,当您键入return nil
时,编译器会推断您的返回类型为void*
。而如果在return
语句之后没有任何内容,或者没有return
,则会推断返回类型为void
,正如参数所预期的那样。
+(void)performGetRequestWithUrl:(NSString *)requestUrl completionHandler:(void (^)(NSDictionary *result, NSError *error))completionBlock