-
Re: Any way to return value in a block
eskimo Nov 18, 2016 2:29 AM (in response to stcocoa)Presumably you have code like this:
BOOL (^b)(int someParam); b = ^(int someParam){ return someParam > 0; };
and are getting this error on line 3. The issue here is that
someParam > 0
is of typeint
, so the inferred type of the block isint (^)(int)
, which is not compatible with the type ofb
, that is,BOOL (^)(int)
.There are two ways to fix this. First, you could force the type of the block:
b = ^BOOL(int someParam){ return someParam > 0; };
Alternatively, you could force the type that you return so that the type of the block in inferred correctly:
b = ^(int someParam){ return (BOOL) (someParam > 0); };
IMPORTANT In this second case I added some parens so that the cast applies to the whole result, not to just
someParam
.Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardwarelet myEmail = "eskimo" + "1" + "@apple.com"
-
Re: Any way to return value in a block
stcocoa Nov 20, 2016 4:52 PM (in response to eskimo)Thank you so much !
I will try to write more code to show my situation so that other people do not need to presume my code..
Thanks again
-