foundationkit / FoundationKit

Everything that really should be in Foundation, but isn't. Future-proof with ARC
Other
80 stars 9 forks source link

Add performBlock afterDelay #29

Closed MSch closed 13 years ago

MSch commented 13 years ago

I'd like to add this category on NSObject

- (void)performBlock:(void (^)())block afterDelay:(NSTimeInterval)delay {
    // For some reason we need [block copy]
    // http://www.mikeash.com/pyblog/friday-qa-2009-08-14-practical-blocks.html
    // http://stackoverflow.com/questions/4007023/blocks-instead-of-performselectorwithobjectafterdelay
    [self performSelector:@selector(_fk_runBlock:) withObject:[block copy] afterDelay:delay];
}

- (void) _fk_runBlock:(void (^)())block; {
    block();
}

Thoughts?

myell0w commented 13 years ago

+1, using this all the time in PSFoundation.

Am 22.07.2011 um 12:41 schrieb MSch:

I'd like to add this category on NSObject

- (void)performBlock:(void (^)())block afterDelay:(NSTimeInterval)delay {
   // For some reason we need [block copy]
   // http://www.mikeash.com/pyblog/friday-qa-2009-08-14-practical-blocks.html
   // http://stackoverflow.com/questions/4007023/blocks-instead-of-performselectorwithobjectafterdelay
   [self performSelector:@selector(_fk_runBlock:) withObject:[block copy] afterDelay:delay];
}

- (void) _fk_runBlock:(void (^)())block; {
   block();
}

Thoughts?

Reply to this email directly or view it on GitHub: https://github.com/foundationkit/FoundationKit/issues/29

eaigner commented 13 years ago

+1 on NSObject category

myell0w commented 13 years ago

fyi: PSFoundation already has such a category including performing blocks with one parameter and canceling blocks (although I never tested the canceling)

myell0w commented 13 years ago

I don't know about you, but I really like BlocksKit from zwaldowski (which also got forked from foundationkit - organization) und will use it in all future Apps. BlocksKit has adapted the category that was used in PSFoundation, which also supports canceling - so I personally don't see the need to redo this in FoundationKit.

MSch commented 13 years ago

I agree that we should use BlocksKit instead of of redoing everything.

IIRC though I needed to patch BlocksKit to make performBlock: work with ARC.