<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Oct 16, 2016, at 11:25 AM, Thierry Passeron via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hello All,<br class=""><br class="">I’m in the process of migrating older code to Swift 3 and I’m stuck on this one.<br class="">How do you create a timer dispatch source?<br class=""><br class="">Old code:<br class=""><br class="">let source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue)<br class=""><br class="">dispatch_source_set_timer(source, dispatch_time(DISPATCH_TIME_NOW, 0), UInt64(interval * 1000_000_000), 0)<br class="">dispatch_source_set_event_handler(source) {<br class=""> &nbsp;&nbsp;// Do something useful<br class=""> }<br class=""><br class=""> dispatch_resume(source)<br class=""><br class="">New code:<br class=""></div></div></blockquote><div><br class=""></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> timer = </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">DispatchSource</span><span style="font-variant-ligatures: no-common-ligatures" class="">.makeTimerSource(queue: queue)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">timer</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">scheduleRepeating</span><span style="font-variant-ligatures: no-common-ligatures" class="">(wallDeadline: .</span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">now</span><span style="font-variant-ligatures: no-common-ligatures" class="">(), interval: .</span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">seconds</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span><span style="font-variant-ligatures: no-common-ligatures" class="">))</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">timer</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures" class="">setEventHandler</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">// Do something useful</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">timer</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures" class="">resume</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">()</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><br class=""></span></div></div><div>Isn’t it nice? It is a pity it is not well documented yet.</div><br class=""><blockquote type="cite" class=""><div class=""><div class="">Xcode is not helping me with any of the required refactoring. The convert tool throws many errors but no proposition.<br class="">I have tried to explore the New Dispatch headers with no luck. DISPATCH_SOURCE_TYPE_TIMER can’t be found… ok so It seems to be replaced with a protocol DispatchSourceTimer and … no initializer… I think I don’t yet catch with the whole philosophy of this new version. <br class=""><br class="">I’d be pleased if anyone cared to enlighten me.<br class=""><br class="">Thanks and regards,<br class="">Thierry<br class=""><br class="">_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></div></blockquote></div><br class=""></div></body></html>