On Jan 28, 2012, at 11:35 AM, Steve Sisak wrote:

>     [self performSelector:@selector(performBlock:)
>                withObject:^{
>         NSLog(@"Done Later");
>     }   afterDelay:1.0];

Don't you need to copy the block? Or is -performSelector:withObject:afterDelay: 
smart enough to know to call -copy instead of -retain on the block?

Also, I'm not entirely happy with this solution because it's tied to an object 
when it shouldn't need to be. So your -doItLater: method only works in the 
class you declare it in, and it has the side effect of keeping the receiver 
alive until the block runs, even if it doesn't need to be (i.e. if the block 
doesn't refer to 'self' at all.)

Someone else had a solution that involved adding a category method to NSObject 
to invoke the block, but that seems a bit kludgy too.

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to