99NS_ASSUME_NONNULL_BEGIN
1010@implementation QCloudGCDTimer
1111
12- static NSMutableDictionary *timers_ ;
13- dispatch_semaphore_t semaphore_ ;
12+ static NSMutableDictionary *qCloud_timers_ ;
13+ dispatch_semaphore_t qCloud_semaphore_ ;
1414
1515/* *
1616 load 与 initialize区别,这里选用initialize
@@ -20,8 +20,8 @@ +(void)initialize{
2020 // GCD一次性函数
2121 static dispatch_once_t onceToken;
2222 dispatch_once (&onceToken, ^{
23- timers_ = [NSMutableDictionary dictionary ];
24- semaphore_ = dispatch_semaphore_create (1 );
23+ qCloud_timers_ = [NSMutableDictionary dictionary ];
24+ qCloud_semaphore_ = dispatch_semaphore_create (1 );
2525 });
2626}
2727
@@ -56,12 +56,12 @@ + (NSString* _Nullable)timerTask:(void(^)(void))task
5656 */
5757 dispatch_source_t timer = dispatch_source_create (DISPATCH_SOURCE_TYPE_TIMER, 0 , 0 , queue);
5858
59- dispatch_semaphore_wait (semaphore_ , DISPATCH_TIME_FOREVER);
59+ dispatch_semaphore_wait (qCloud_semaphore_ , DISPATCH_TIME_FOREVER);
6060 // 定时器的唯一标识
61- NSString *timerName = [NSString stringWithFormat: @" %zd " , timers_ .count];
61+ NSString *timerName = [NSString stringWithFormat: @" %zd " , qCloud_timers_ .count];
6262 // 存放到字典中
63- timers_ [timerName] = timer;
64- dispatch_semaphore_signal (semaphore_ );
63+ qCloud_timers_ [timerName] = timer;
64+ dispatch_semaphore_signal (qCloud_semaphore_ );
6565
6666 dispatch_source_set_timer (timer, dispatch_time (DISPATCH_TIME_NOW, start * NSEC_PER_SEC), interval * NSEC_PER_SEC, 0 );
6767 dispatch_source_set_event_handler (timer, ^{
@@ -111,17 +111,18 @@ +(void)canelTimer:(NSString*) timerName{
111111 return ;
112112 }
113113
114- dispatch_semaphore_wait (semaphore_ , DISPATCH_TIME_FOREVER);
114+ dispatch_semaphore_wait (qCloud_semaphore_ , DISPATCH_TIME_FOREVER);
115115
116- dispatch_source_t timer = timers_ [timerName];
116+ dispatch_source_t timer = qCloud_timers_ [timerName];
117117 if (timer) {
118118 dispatch_source_cancel (timer);
119- [timers_ removeObjectForKey: timerName];
119+ [qCloud_timers_ removeObjectForKey: timerName];
120120 }
121121
122- dispatch_semaphore_signal (semaphore_ );
122+ dispatch_semaphore_signal (qCloud_semaphore_ );
123123
124124}
125125
126126@end
127127NS_ASSUME_NONNULL_END
128+
0 commit comments