티스토리 뷰
학습내용
Error Handling
문제점/고민한점 → 해결방안
과일 재고 업데이트를 과일쥬스에 필요한 재고만 업데이트 할 방법은?
for 문으로 하려다가 더 복잡해지는 것 같아서 fail
let order = [JuiceTypes.strawberryJuice, JuiceTypes.bananaJuice, JuiceTypes.mangoJuice, JuiceTypes.mangoKiwiJuice, JuiceTypes.strawberryBananaJuice, JuiceTypes.kiwiJuice, JuiceTypes.pineappleJuice,] for Juice in order { if orderdJuice == Juice { "\(Juice)Stock".text = String(juiceMaker.fruitInformation[]!.stock)
switch 문
기존 코드
func updateStock() { strawberryStock.text = String(juiceMaker.fruitInformation[.banana]!.stock) bananaStock.text = String(juiceMaker.fruitInformation[.banana]!.stock) pineappleStock.text = String(juiceMaker.fruitInformation[.pineapple]!.stock) kiwiStock.text = String(juiceMaker.fruitInformation[.kiwi]!.stock) mangoStock.text = String(juiceMaker.fruitInformation[.mango]!.stock) }
변경 코드
func updateStock(orderdJuice: JuiceTypes) { switch orderdJuice { case .strawberryJuice: if let fruit = juiceMaker.fruitInformation[.strawberry] { strawberryStock.text = String(fruit.stock) } else { fatalError() } case .strawberryBananaJuice: if let fruit = juiceMaker.fruitInformation[.strawberry] { strawberryStock.text = String(fruit.stock) } else { fatalError() } if let fruit = juiceMaker.fruitInformation[.banana] { bananaStock.text = String(fruit.stock) } else { fatalError() } }
너무 깊어져서 method로 빼면 좋을듯...
더 좋은 방법이 있을지...!
alert로 화면전환은 어떻게 할 수 있을까?
-
let pushVC = self.storyboard?.instantiateViewController(withIdentifier: "vcStoaryBoardID") self.navigationController?.pushViewController(pushVC!, animated: true)
hailey의 도움으로 어케저케는 된 거 같은데 이건 또 다 무슨뜻인가...!
기타 (알아봐야할 사항)
- swift UI는 교재가 있어야 되나? → 키워드 검색의 어려움.
- Notification Center, KVO, delegate 3개의 차이점 알기
'TIL' 카테고리의 다른 글
TIL ('21.03.22) (0) | 2021.03.22 |
---|---|
TIL ('21.03.18) - iOS View Life Cycle (0) | 2021.03.18 |
TIL ('21.03.15) (0) | 2021.03.16 |
TIL ('21.03.12) (0) | 2021.03.14 |
TIL ('21.03.11) (0) | 2021.03.12 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 반복문
- Constants
- playground
- 전산구문 기초용어
- conditional
- 구문이름표
- swift
- scope
- 산술연산자
- variables
- 삼항연산자
- labeled
- 범위연산자
- continue
- 비트연산자
- 흐름제어구문
- overflow
- 훈련법
- RawValues
- 오토레이아웃
- 결합성
- datatypes
- Functions
- 오버플로우연산자
- 세자리수마다 콤마넣기
- 옵셔널
- iOS View Life Cycle
- optional
- enumerations
- 객체지향 생활체조
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함