前提・実現したいこと
swiftでタイマーを作りたいです。
スタート、ストップ、リセットができるものを作ろうとしています。また、測った時間を保存してグラフに表したい
発生している問題・エラーメッセージ
ストップさせるためにif timer != nil{
timer.invalidate()を書いたらタイマーは止まるのですがビルドが中断して落ちてしまいます。
今はおそらく他のエラーも重なりBuild Failedになってしまいます。どうしたらいいでしょうか。
また、このような2つのエラーが出ているのですがどのように対処したらいいですか?
Value of type 'ViewController2' has no member 'timerCounter'
Use of unresolved identifier 'overide
エラーメッセージ Value of type 'ViewController2' has no member 'timerCounter' Use of unresolved identifier 'overide swift import UIKit class ViewController2: UIViewController { weak var timer: Timer! //追加 var startTime = Date() @IBOutlet weak var minute: UILabel! @IBOutlet weak var seconds: UILabel! @IBOutlet weak var miniSeconds: UILabel! override func viewDidLoad() { super.viewDidLoad() } @IBAction func start(_ sender: Any) { if timer != nil{ timer.invalidate() } timer = Timer.scheduledTimer( timeInterval: 0.01, target: self, selector: #selector(self.timerCounter), userInfo: nil, repeats: true) startTime = Date() } @IBAction func reset(_ sender: Any) { if timer != nil{ timer.invalidate() minute.text = "00" seconds.text = "00" miniSeconds.text = "00" } } @IBAction func stoptimer(_ sender: Any) { timer.invalidate() print(timer.isValid) } @IBAction func furoru(_ sender: Any) { func timerCounter() { let currentTime = Date().timeIntervalSince(startTime) let minutelo = (Int)(fmod((currentTime/60), 60)) let second = (Int)(fmod(currentTime, 60)) let msec = (Int)((currentTime - floor(currentTime))*100) let sMinute = String(format:"%02d", minutelo) let sSecond = String(format:"%02d", second) let sMsec = String(format:"%02d", msec) minute.text = sMinute seconds.text = sSecond miniSeconds.text = sMsec } overide; func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } } }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。