2017-06-30 9 views
1
let duration = 10 
self.configureTimer(startTime: Date(), duration: duration) 
self.countdownTimer.start() 

、実行を切り替える方法として、以下の2つの方法の間、30秒ごとに:30秒ごとにNSTimerに基づいて実行を切り替えるにはどうすればよいですか?上記のコードでは

func first30Seconds() { } 
func next30Seconds() { } 

基本的に私は30秒ごとのための上記の二つの方法first30Secondsnext30Seconds切り替えるしようとしていることタイマーは刻々と変化しています。あなたの助けに大いに感謝します。

+0

どのくらいの頻度であなたのタイマーが刻々と過ぎている。そして、30秒後に他のを呼び出すために、両方の機能を更新

var timer: Timer! 

? 10秒ごとに? – Paulw11

+0

@ Paulw11 1秒に1回目を刻んでいます。ありがとうございました。 –

答えて

1

でタイマーインスタンスを追跡します:

func first30Seconds() { 
    timer = Timer.scheduledTimer(timeInterval: 30, target: self, selector: #selector(second30Seconds), userInfo:nil, repeats: false) 
    // Other code... 
} 
func second30Seconds() { 
    timer = Timer.scheduledTimer(timeInterval: 30, target: self, selector: #selector(first30Seconds), userInfo:nil, repeats: false) 
    // Other code... 
} 
関連する問題