스위프트 1.2로 작성된 타이머를 만드는 Grad Central Dispatch 클래스가 있습니다. 스위프트 3으로 변환하려고하는데 스위프트 3으로 다시 작성하는 방법을 찾을 수 없습니다.스위프트 3 - 도움말 GCD 클래스 변환
어떤 도움이 필요하십니까? 여기
class GCDTimer {
private var _timer : dispatch_source_t?
init() {
}
private func _createTheTimer(interval : Double, queue : dispatch_queue_t, block : (() -> Void)) -> dispatch_source_t
{
let timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
if (timer != nil)
{
dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, Int64(interval * Double(NSEC_PER_SEC))), UInt64(interval * Double(NSEC_PER_SEC)), (1 * NSEC_PER_SEC)/10);
dispatch_source_set_event_handler(timer, block);
dispatch_resume(timer);
}
return timer;
}
func start(interval : Double, block : (() -> Void))
{
let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
_timer = _createTheTimer(interval, queue: queue, block: block)
}
func stop()
{
if (_timer != nil) {
dispatch_source_cancel(_timer!);
_timer = nil;
}
}
}
너무 넓습니다. 스택 오버플로는 번역 서비스가 아닙니다. "다시 쓰는 방법을 찾을 수 없습니다"는 실제 문제가 아닙니다. "이것에 어떤 도움이 필요합니까?" 진짜 질문이 아닙니다. 특정 문제/오류가 있으면 그들 중 하나에 대해 물어보십시오. - 한편, 여기에 내 자신의 GCD 기반 타이머가 있습니다. 그것을 자유롭게 사용하십시오. https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk1ch12p499cancelableTimer/ch12p325NotificationLeaker/CancelableTimer.swift – matt
@matt iOS 관련 항목이 많아서 무엇이 잘못되었는지 알 수 있습니까? 내 대답은? – silentBob