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: Kyle Sluder <email@hidden>
- Date: Fri, 17 Sep 2010 19:21:17 -0700
On Fri, Sep 17, 2010 at 7:07 PM, ico <email@hidden> wrote:
> 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?
I don't know what you're asking for here. You got the block as an
argument just like any other argument.
@implementation MyClass
- (void)doSomethingWithBlock:(void (^)(id string1, id string2))aBlock {
aBlock(@"hello", @"world");
}
@end
@implementation SomeOtherClass
- (void)anotherMethod {
anObject = [[MyClass alloc] init];
[anObject doSomethingWithBlock:^(id foo, id bar) {
NSLog(@"foo=%@, bar=%@", foo, bar); // will output "foo=hello bar=world"
}];
}
@end
--Kyle Sluder
_______________________________________________
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