• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Stupid block syntax!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Stupid block syntax!
      • From: Graham Cox <email@hidden>
References: 
 >Stupid block syntax! (From: Graham Cox <email@hidden>)

  • Prev by Date: Stupid block syntax!
  • Next by Date: Re: Stupid block syntax!
  • Previous by thread: Stupid block syntax!
  • Next by thread: Re: Stupid block syntax!
  • Index(es):
    • Date
    • Thread