Re: How to invoke and inline block which is passed as function argument
Re: How to invoke and inline block which is passed as function argument
- Subject: Re: How to invoke and inline block which is passed as function argument
- From: Dave DeLong <email@hidden>
- Date: Fri, 17 Sep 2010 13:35:19 -0600
Just like you would with a function pointer:
- (void) executeBlock:(void(^)(NSString * param))block {
block(@"Hello world!");
}
Cheers,
Dave
On Sep 17, 2010, at 1:32 PM, ico wrote:
> Hi All,
>
> I just wonder how to invoke an inline block which is passed as function
> argument.
> We can invoke a block if we declare a block as a variable, what if you
> simply implement
> them inline where they are required as an argument. It seems you have
> nothing reference
> to that block address.
>
> For example, NSArray class has a method as follow:
> - (NSArray *)sortedArrayUsingComparator:(NSComparator)*cmptr*
> *
> *
> *the argument cmptr can simply be an inline block like:*
> *[stringsArray sortedArrayUsingComparator:^(id string1, id string2) {*
> * blah, blah;*
> *}];*
> *
> *
> *I just wonder inside the sortedArrayUsingComparator method, how to call
> that block for*
> *comparing two string since you don't have a reference to it. Another
> example is qsort_b*
> function. I just can't find the source code for those two methods.
>
> Thanks for your help in advance.
>
> --
> ==========================
> Life isn't about finding yourself.
> Life is about creating yourself.
> _______________________________________________
>
> 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
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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