LoginSignup
10
9

More than 5 years have passed since last update.

Blocksの遅延実行 - performBlock: afterDelay:

Last updated at Posted at 2012-07-03

NSObject のカテゴリあたりに。

/*!
 * @method performBlock:afterDelay:
 */
- (void)performBlock:(void (^)(void))block afterDelay:(NSTimeInterval)delay {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC), dispatch_get_current_queue(), block);
}

/*!
 * @method performBlock:withObject:afterDelay:
 */
- (void)performBlock:(void (^)(id obj))block withObject:(id)object afterDelay:(NSTimeInterval)delay {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC), dispatch_get_current_queue(), ^{block(object);});
}

参考

10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9