Stupid block syntax!
Stupid block syntax!
- Subject: Stupid block syntax!
- From: Graham Cox <email@hidden>
- Date: Wed, 04 Jul 2012 15:40:06 +1000
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