diff --git a/EggTimer/Base.lproj/Main.storyboard b/EggTimer/Base.lproj/Main.storyboard index 2df29d93..0051f75e 100644 --- a/EggTimer/Base.lproj/Main.storyboard +++ b/EggTimer/Base.lproj/Main.storyboard @@ -1,9 +1,11 @@ - + - + + + @@ -21,9 +23,9 @@ - + @@ -122,8 +149,11 @@ - + + + + @@ -134,5 +164,11 @@ + + + + + + diff --git a/EggTimer/ViewController.swift b/EggTimer/ViewController.swift index 0d9d8d79..75b50d25 100644 --- a/EggTimer/ViewController.swift +++ b/EggTimer/ViewController.swift @@ -7,9 +7,66 @@ // import UIKit +import AVFoundation class ViewController: UIViewController { + @IBOutlet weak var textLabel: UILabel! + + @IBOutlet weak var progressBar: UIProgressView! + + + + let eggTime = ["Soft": 10, "Medium": 420, "Hard": 720] + var totalTime = 0; + var secondsPassed = 0 + let timer = Timer() + var player = AVAudioPlayer() + + @IBAction func hardEgg(_ sender: UIButton) { + + let hardness = sender.currentTitle + + totalTime = eggTime[hardness!]! + + Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: true) + + + switch hardness { + case "Soft": + print(eggTime[hardness!]!) + + + case "Medium": + print(eggTime[hardness!]!) + + case "Hard": + print(eggTime[hardness!]!) + + default: + print("Error") + } + } + + @objc func updateTimer(){ + if secondsPassed < totalTime { + + let percentageProgress = Float(secondsPassed) / Float(totalTime) + print("\(percentageProgress)") + progressBar.progress = percentageProgress + + secondsPassed += 1 + } else { + timer.invalidate() + textLabel.text = "DONE BC!" + let path = Bundle.main.path(forResource: "alarm_sound", ofType : "mp3")! + let url = URL(fileURLWithPath : path) + do { + player = try AVAudioPlayer(contentsOf: url) + player.play() + } catch { + print ("There is an issue with this code!") + } + } + } - - }