2017-11-18 8 views
-3

Xcodeプロジェクトで生まれてからの秒数を表示しようとしています。私の現在のコードは1秒ごとに変更することなく1つの数字だけを表示します。私がループに入れるとMain.storyboardはロードされません。毎秒番号を更新するにはどうすればよいですか? 。速やかに1秒ごとに計算を繰り返すにはどうすればよいですか?

This is my code

+0

を使うとどのようにhttps://developer.apple.com/documentation/foundation/nstimer/1412416-scheduledtimerwithtimeinterval – Brandon

+3

可能な重複して使用することが非常に簡単な例SwiftでNSTimerを使用できますか?](https://stackoverflow.com/questions/24007518/how-can-i-use-nstimer-in-swift) – ozgur

+2

画像を投稿しないでください。投稿テキスト。そしてあなたの '....チェンジ'数学は恐ろしいです。適切な「カレンダー」の方法を使用してください。 – vadian

答えて

0

遊び場

import PlaygroundSupport 
PlaygroundPage.current.needsIndefiniteExecution = true 

let calendar = Calendar.current 
let components = DateComponents(year: 2003, month: 7, day: 2, hour: 6, minute: 33, second: 17) 
let birthDate = calendar.date(from: components)! 
Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { timer in 
    let totalSecondChange = calendar.dateComponents([.second], from: birthDate, to: Date()).second! 
    print(totalSecondChange) 
} 
関連する問題