• 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
Stupid block syntax!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Stupid block syntax!
      • From: Lee Ann Rucker <email@hidden>
    • Re: Stupid block syntax!
      • From: Quincey Morris <email@hidden>
    • Re: Stupid block syntax!
      • From: Charles Srstka <email@hidden>
    • Re: Stupid block syntax!
      • From: Ken Thomases <email@hidden>
    • Re: Stupid block syntax!
      • From: Roland King <email@hidden>
  • Prev by Date: [MEET] Toronto Cocoaheads / tacow - July 10
  • Next by Date: Re: Stupid block syntax!
  • Previous by thread: [MEET] Toronto Cocoaheads / tacow - July 10
  • Next by thread: Re: Stupid block syntax!
  • Index(es):
    • Date
    • Thread