I just played quickly with blocks today, and I came across an 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
Since I really wanted to return nil if "1" or "2" were not entered, I decided to simply return the final return back to NSString using:
NSString *(^testBlock)(int) = ^(int option) { if (option == 1) return @"ONE"; if (option == 2) return @"TWO"; return (NSString *) nil; };
This works fine, I was just wondering if this was the right decision or even bad practice, since I had never thought about pouring zero before?
objective-c iphone cocoa-touch objective-c-blocks
fuzzygoat
source share