삶은 계란 타이머 프로젝트

1 답변 글타래를 보이고 있습니다
  • 글쓴이
    • zeepada
      참가자
      • 글작성 : 7
      • 답글작성 : 2

      계란 삶기 Soft-Medium-Hard에 따른 타이머

      (Udemy Angela Yu iOS Bootcamp 섹션8)

      012

      Soft 300초 Medium 420초 Hard 720초 세팅, 각 버튼 클릭시 timer로 시간을 카운트 합니다.

       

      progress bar → 시간 퍼센테이지 보여주기 (버튼 클릭 후 경과 시간/해당 삶기 total 시간)

      *progressview 0.0(0%) → 1.0(100%)

      Label → 1. 타이머 동작 중에는 삶기 종류 text / 2. 타이머 종료 후 Done! text

      Sound → 타이머 종료 후 알람mp3 실행

       


      // //  ViewController.swift //  EggTimer // //  Created by Angela Yu on 08/07/2019. //  Copyright © 2019 The App Brewery. All rights reserved. // import UIKit import AVFoundation class ViewController: UIViewController {   var player: AVAudioPlayer?   @IBOutlet var progressBar: UIProgressView! @IBOutlet var titleLabel: UILabel!   let eggTimes = ["Soft":3, "Medium":420, "Hard": 720] var timer = Timer() var totalTime = 0 var secondsPassed = 0     @IBAction func hardnessSelected(_ sender: UIButton) {   timer.invalidate() let hardness = sender.currentTitle! totalTime = eggTimes[hardness]!   progressBar.progress = 0.0 secondsPassed = 0 titleLabel.text = hardness   timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: true) }   @objc func updateTimer() { if secondsPassed < totalTime { secondsPassed += 1 progressBar.progress = Float(secondsPassed) / Float(totalTime)   } else { timer.invalidate() titleLabel.text = "Done!" playSound() } }   func playSound() { let url = Bundle.main.url(forResource: "alarm_sound" , withExtension: "mp3") player = try! AVAudioPlayer(contentsOf: url!) player?.play()   }   }

       

      디바이스 크기에 폰트 맞추기

      Lines: 0 → 줄바꿈 가능하게
      Autoshrink → Minimum Font Size (15) 설정

       

       

      *지난 게시글에 야곰님이 남겨주신 강제추출에 대한 피드백을 이제야 봤네요 🙁 다음 프로젝트부터는 좀 더 공부해서 강제추출 지양하도록 하겠습니다!

      *야곰 스터디가 아니였다면 업무에 지쳐 iOS 공부를 할 엄두도 못냈을 것 같은데, 스터디 덕분에 부족한 양이긴 하지만 일주일마다 꾸준히 할 수 있어서 너무 좋은 것 같습니다. 감사합니다 🙂

      *내일부터는 출근 전 조금이라도 매일 꾸준히 공부하도록 노력해보겠습니다.

      • 이 게시글은 zeepada에 의해 4 years 전에 수정됐습니다.
      • 이 게시글은 zeepada에 의해 4 years 전에 수정됐습니다.
      • 이 게시글은 zeepada에 의해 4 years 전에 수정됐습니다.
      • 이 게시글은 zeepada에 의해 4 years 전에 수정됐습니다.
    • 야곰
      키 마스터
      • 글작성 : 37
      • 답글작성 : 579

      피드백 고맙습니다 ㅎㅎ 보람이 있네요!

      코드를 이렇게 바꿔보면 어떨까요?

      1. totalTimesecondsPassed를 애초에 Float 타입으로 선언해주는 것은 어떨까요?
      2. eggTimes를 딕셔너리 대신 좀 더 구체적인 구조체의 세트 정도로 구현해 보는 것은 어떨까요? (선택의 문제라 뭐가 더 좋고 나쁨은 없습니다만, 코드의 요류를 줄일 수 있고, 하드코딩을 줄여볼 수 있습니다)
      3. Autoshrink → Minimum Font Size (15) 설정 보다는 Dynamic Type에 대해 알아보면 훨씬 좋을 것 같습니다 🙂
1 답변 글타래를 보이고 있습니다
  • 답변은 로그인 후 가능합니다.

logo landscape small

사업자번호 : 743-81-02195
통신판매업 신고번호 : 제 2022-충북청주-1278 호
고객센터 : 카카오톡채널 @yagom