1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

逆引きReactiveCocoa: 毎時0分に処理を行う

Posted at

元ネタ: ios - Perform action on the hour, every hour, with ReactiveCocoa - Stack Overflow


現在時刻から1時間毎だと毎時0分とならないので、まずは次の時までの分を得ておきます。

NSDateComponents *components = [[[NSCalendar sharedCalendar] calendar] components:NSMinuteCalendarUnit fromDate:[NSDate date]];
NSInteger minutesToNextHour = 60 - components.minute;

いったん現在時刻から次の時までのタイマーシグナルを生成し、1回限りで終了させた後に改めて60分間隔のタイマーシグナルを繋げて完成です。

RACSignal *updateEventSignal = [[[RACSignal
    // `+interval:`の引数は`NSTimeInterval`で秒単位。
    interval:(60 * minutesToNextHour)]
    take:1]
    concat:[RACSignal interval:3600]];
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?