Alejandro Martinez

BlogPodcastPortfolio Youtube

03 May, 2016Development🕐 1min read

Quick and dirty debug timer

For those occasions when you need to check something some state at regular intervals.

Just drop this snippet at the top of your file:

static dispatch_source_t timer;
void DebugTimer(dispatch_block_t block)
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    double interval = 1;
    timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
    dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, (int64_t)interval * NSEC_PER_SEC), (int64_t)interval * NSEC_PER_SEC, (1ull * NSEC_PER_SEC) / 10);
    dispatch_source_set_event_handler(timer, block);

And then call this procedure, for example, in viewDidLoad:

    NSLog(@"What is wrong with you? %@", vipView);

Remember, this is just for debugging purposes.

👉🏻 If you have any feedback you can reach me at alexito4

MIR, the new Rust mid-level IROn teaching C

Alejandro Martinez

Buka pintu