Re: Block error
Re: Block error
- Subject: Re: Block error
- From: Gwynne Raskind <email@hidden>
- Date: Fri, 15 Jul 2011 21:35:38 -0400
On Fri, Jul 15, 2011 at 7:53 PM, Rick Mann <email@hidden> wrote:
>> Learning this stuff myself and want to confirm I'm following this (don't have Xcode handy), would the code below avoid the error since the one return clearly returns a Foo*?
>>
>> (id) ^(id inParam1)
>> {
>> Foo* foo = nil;
>>
>> if ([inParam1 isEqual: @"baz"])
>> {
>> foo = [[Foo alloc] init];
>> }
>>
>> return foo;
>> };
>
> yes, this works.
To my knowledge, the "correct" way to declare a block's return type is like so:
^ returntype (params) { code }
So the above example would become:
^ id (id inParam1) {
Foo *foo = nil;
if ([inParam1 isEqual:@"baz"])
foo = [[Foo alloc] init];
return foo;
};
And you can typedef and cast a block using the standard
pointer-to-function cast syntax:
id (^foob)(id) = ^ id (id inParam1) { ... };
typedef id (^FooBlock)(id);
FooBlock foob = ^ id (id inParam1) { ... };
-- Gwynne
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden