当前位置:首页 > 图灵资讯 > 技术篇> iOS GCD 定时器
iOS GCD 定时器
发布时间:2023-05-23 09:24:29
dispatch_queue_t queue = dispatch_queue_create("serial", DISPATCH_QUEUE_SERIAL); self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); dispatch_time_t start = dispatch_time(DISPATCH_TIME_NOW, 0); uint64_t interval = (uint64__t)(1.0 * NSEC_PER_SEC); dispatch_source_set_timer(self.timer, start, interval, 0); dispatch_source_set_event_handler(self.timer, ^{ static int i = 0; i++; NSLog(@"currentThread is %@", [NSThread currentThread]); NSLog(@"i is %d", i); if (i == 4) { dispatch_cancel(self.timer); self.timer = nil; } }); dispatch_resume(self.timer);
ps 图灵课堂老师从近一百套最新一线互联网公司面试题中精选而出,涵盖Java架构面试 所有技术栈,包括JVM,Mysql,并发,Spring,Redis,MQ,Zookeeper,Netty, Dubbo,Spring Boot,Spring Cloud,数据结构与算法,设计模式等相关技术领域的大 厂面试题及详解。 详情咨询客服获取全套面经试题。