Last active
August 29, 2015 14:03
-
-
Save srpoucse/cf0c85113498dd24aa6f to your computer and use it in GitHub Desktop.
Revisions
-
srpoucse renamed this gist
Jul 8, 2014 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ #define TIME_INTERVAL_TO_FIRE 15 * NSEC_PER_SEC #import <Foundation/Foundation.h> -
srpoucse created this gist
Jul 8, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ #define TIME_INTERVAL_TO_FIRE 15 * NSEC_PER_SEC #import <Foundation/Foundation.h> @interface SampleClass : NSObject { dispatch_source_t timer; } - (void)startTimer; - (void)cancelTimer; @end #import "SampleClass.h" @implementation SampleClass { dispatch_source_t _timer; } - (void)startTimer { dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0); timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); dispatch_source_set_timer(timer, DISPATCH_TIME_NOW,TIME_INTERVAL_TO_FIRE , (1ul * NSEC_PER_SEC)/10); dispatch_source_set_event_handler(timer, ^ { //do something }); dispatch_resume(timer); } - (void)cancelTimer { if (timer) { dispatch_source_cancel(timer); timer = nil; } } @end