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 <graham....@bigpond.com> 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 (Cocoa-dev@lists.apple.com) > > 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: > https://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org > > This email sent to r...@rols.org _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com