• 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: Graham Cox <email@hidden>
  • Date: Wed, 04 Jul 2012 22:13:01 +1000

On 04/07/2012, at 3:50 PM, Roland King wrote:

> Put 'NSComparisonResult' after = and before ^ to declare the return value of the block in the code below.


That didn't work, but after a few more wild guesses, I stumbled on the correct form:

	NSComparisonResult (^comp)( id<DKStorableObject>, id<DKStorableObject> ) = ^NSComparisonResult( id<DKStorableObject> a, id<DKStorableObject> b )
	{
		if( a.index < b.index )
			return NSOrderedAscending;
		else if ( a.index > b.index )
			return NSOrderedDescending;
		else
			return NSOrderedSame;
	};





>
> When that fails. Err. Not sure.


That's the trouble - when it doesn't work, even when you follow the examples in the documentation apparently to the letter, you're stuck.


On 04/07/2012, at 4:12 PM, Ken Thomases wrote:

> t follows the general form for C declarations, such as for function pointers.  However, blocks can be defined in different contexts than functions, which makes it seem out of place.  In general, try writing it exactly as though you were writing a function.  Then replace the function name with either "^" or, when defining a variable or typedef, "(^name_of_variable_or_typedef)".


OK, that's a handy bit of help. Mind you, function pointers themselves are not always that easy to get right, though I haven't run into anywhere near as much trouble with them as I have with blocks.

Thanks for all the advice,

--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: Roland King <email@hidden>
References: 
 >Stupid block syntax! (From: Graham Cox <email@hidden>)
 >Re: Stupid block syntax! (From: Roland King <email@hidden>)

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