Waiting for a specified duration in Cocoa

前端 未结 7 1891
生来不讨喜
生来不讨喜 2020-12-29 03:41

Is there a more straightforward way to wait for a specific amount of time in Cocoa than what I have come up with below?

- (void) buttonPressed {
    [self ma         


        
相关标签:
7条回答
  • 2020-12-29 04:09

    I'm not sure if it exists (yet), but with blocks in 10.6 (or PLBlocks in 10.5 and on the iPhone) it should be pretty easy to write a little wrapper like performBlock:afterDelay: that does exactly what you want without the need to sleep the entire thread. Would be a useful little piece of code indeed.

    Mike Ash has written about an approach like this on his blog:

    NSString *something = ...;
    RunAfterDelay(0, ^{
        NSLog(@"%@", something);
        [self doWorkWithSomething: something];
    });
    
    0 讨论(0)
提交回复
热议问题