I was just quickly playing with blocks today and I came across the error:
NSString *(^testBlock)(int) = ^(int option) {
if (option == 1) return @"ONE";
if (option == 2) return @"TWO";
return nil;
};
NSLog(@"OUTPUT: %@", testBlock(4));
Return type 'void *' must match previous return type 'NSString *' when block literal has unspecified explicit return type
As I really wanted to return nil if "1" or "2" were not input I decided to simply cast the final return back to an NSString using:
NSString *(^testBlock)(int) = ^(int option) {
if (option == 1) return @"ONE";
if (option == 2) return @"TWO";
return (NSString *) nil;
};
This works just fine, I was just curious if this was the correct solution or even bad practice as I have never thought about casting nil before?