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: ico <email@hidden>
- Date: Sat, 18 Sep 2010 10:07:16 +0800
Hi Dave,
I think you misunderstood me, if a block declared with a block variable
reference to it, of
course we can call it like we would with a function pointer. What I don't
know how to invoke
the block is the case which we don't even have a function pointer to it,
this happens when
we implement an inline block, such as:
stringsArray sortedArrayUsingComparator:^(id string1, id string2) {
blah, blah;
}];
inside the sortedArrayUsingComparator implementation, we have an argument
which is a
block, but in this case, that is an inline block, just block arguments are
declared(string1 and
string2), we don't have a block variable though. So inside the
sortedArrayUsingComparator
implementation, how we can invoke that block?
On Sat, Sep 18, 2010 at 3:35 AM, Dave DeLong <email@hidden> wrote:
> 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
>
>
--
==========================
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