Re: Stupid block syntax!
Re: Stupid block syntax!
- Subject: Re: Stupid block syntax!
- From: Roland King <email@hidden>
- Date: Wed, 04 Jul 2012 13:50:30 +0800
Put 'NSComparisonResult' after = and before ^ to declare the return value of the block in the code below.
When that fails. Err. Not sure.
> NSComparisonResult (^comp)( id<DKStorableObject>, id<DKStorableObject> ) = ^( id<DKStorableObject> a, id<DKStorableObject> b ) {
On 4 Jul, 2012, at 13:40, Graham Cox <email@hidden> wrote:
> Why doesn't this compile?
>
>
> NSComparisonResult (^comp)( id<DKStorableObject>, id<DKStorableObject> ) = ^( id<DKStorableObject> a, id<DKStorableObject> b )
> {
> if( a.index < b.index )
> return NSOrderedAscending;
> else if ( a.index > b.index )
> return NSOrderedDescending;
> else
> return NSOrderedSame;
> };
>
> error: incompatible block pointer types initializing 'NSComparisonResult (^)(id<DKStorableObject>, id<DKStorableObject>)' with an expression of type 'int (^)(id<DKStorableObject>, id<DKStorableObject>)'
>
> Why does it assume that the return type is 'int"? There is nothing here that appears to suggest it is one. NSComparisonResult is a typedef of NSInteger. If I attempt to cast the result, I get an equally baffling error:
>
> error: invalid block pointer conversion initializing 'NSComparisonResult (^)(id<DKStorableObject>, id<DKStorableObject>)' with an expression of type 'NSComparisonResult' (aka 'long')
>
> I see there is a typedef for a generic comparator already, but I want to declare it as conforming to a protocol.
>
>
> Could the stupid block syntax be any less intuitive?
>
> --Graham
>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden