On Fri, Sep 17, 2010 at 7:07 PM, ico <jche...@gmail.com> 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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com