Alexito's World

A world of coding 💻, by Alejandro Martinez

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 dispatchsourcet timer; void DebugTimer(dispatchblockt block) { dispatchqueuet queue = dispatchgetglobalqueue(DISPATCHQUEUEPRIORITYDEFAULT, 0); double interval = 1; timer = dispatchsourcecreate(DISPATCHSOURCETYPETIMER, 0, 0, queue); dispatchsourcesettimer(timer, dispatchtime(DISPATCHTIMENOW, (int64t)interval NSECPERSEC), (int64t)interval NSECPERSEC, (1ull NSECPERSEC) / 10); dispatchsourceseteventhandler(timer, block); dispatch_resume(timer); }

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

DebugTimer(^{ NSLog(@"What is wrong with you? %@", vipView); });

Remember, this is just for debugging purposes.