Repository navigation
쥬스 메이커 [STEP 2] sookoong, bard #227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
942a582
a6d4a12
c3aacdb
d39f37b
ea3ae4e
331aa67
2ef77eb
c15db26
a74f08c
4668ca2
ccccc58
d452d18
0c24f6a
e91e816
b05c56e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ | |
| C71CD66B266C7ACB0038B9CB /* FruitStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = C71CD66A266C7ACB0038B9CB /* FruitStore.swift */; }; | ||
| C73DAF37255D0CDD00020D38 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C73DAF36255D0CDD00020D38 /* AppDelegate.swift */; }; | ||
| C73DAF39255D0CDD00020D38 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C73DAF38255D0CDD00020D38 /* SceneDelegate.swift */; }; | ||
| C73DAF3B255D0CDD00020D38 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C73DAF3A255D0CDD00020D38 /* ViewController.swift */; }; | ||
| C73DAF3B255D0CDD00020D38 /* JuiceOrderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C73DAF3A255D0CDD00020D38 /* JuiceOrderViewController.swift */; }; | ||
| C73DAF3E255D0CDD00020D38 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C73DAF3C255D0CDD00020D38 /* Main.storyboard */; }; | ||
| C73DAF40255D0CDE00020D38 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C73DAF3F255D0CDE00020D38 /* Assets.xcassets */; }; | ||
| C73DAF43255D0CDF00020D38 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C73DAF41255D0CDF00020D38 /* LaunchScreen.storyboard */; }; | ||
|
|
@@ -29,7 +29,7 @@ | |
| C73DAF33255D0CDD00020D38 /* JuiceMaker.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JuiceMaker.app; sourceTree = BUILT_PRODUCTS_DIR; }; | ||
| C73DAF36255D0CDD00020D38 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; | ||
| C73DAF38255D0CDD00020D38 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; }; | ||
| C73DAF3A255D0CDD00020D38 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; }; | ||
| C73DAF3A255D0CDD00020D38 /* JuiceOrderViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JuiceOrderViewController.swift; sourceTree = "<group>"; }; | ||
| C73DAF3D255D0CDD00020D38 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; }; | ||
| C73DAF3F255D0CDE00020D38 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; | ||
| C73DAF42255D0CDF00020D38 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; }; | ||
|
|
@@ -56,7 +56,7 @@ | |
| children = ( | ||
| C73DAF36255D0CDD00020D38 /* AppDelegate.swift */, | ||
| C73DAF38255D0CDD00020D38 /* SceneDelegate.swift */, | ||
| C73DAF3A255D0CDD00020D38 /* ViewController.swift */, | ||
| C73DAF3A255D0CDD00020D38 /* JuiceOrderViewController.swift */, | ||
| ); | ||
| path = Controller; | ||
| sourceTree = "<group>"; | ||
|
|
@@ -138,6 +138,14 @@ | |
| C73DAF2B255D0CDC00020D38 /* Project object */ = { | ||
| isa = PBXProject; | ||
| attributes = { | ||
| KnownAssetTags = ( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 질문이 있습니다🙋
중에 어떤 것이 더 유지보수에서 편리할 것이라고 생각하는지, 왜 그렇게 생각하는지 수꿍과 바드의 의견이 궁금합니다.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아무래도 IBAction함수를 각각 선언해주면 코드만 보아도 이해를 할 수 있지만, tag나 currentTitle을 사용한다면, 다른 파일 내에서도 어떻게 tag나 currentTitle를 달았는지 확인을 해봐야 할 것 같습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋습니다👏 앞으로의 프로젝트에서 스토리보드를 통해서 협업을 해보는 경험과 또 코드로 화면을 구현하는 협업을 경험을 해보시면서 직접 느껴보시는 것을 추천드립니다! 물론 둘 중에 뭐가 더 좋다 라는 정답은 당연히 없고, 둘 가지 방법 모두 사용되는 방법이니 두 방법을 잘 사용할 줄 알아야합니다 🙏🏻 |
||
| 0, | ||
| 1, | ||
| 2, | ||
| 3, | ||
| 4, | ||
| 5, | ||
| ); | ||
| LastSwiftUpdateCheck = 1200; | ||
| LastUpgradeCheck = 1200; | ||
| TargetAttributes = { | ||
|
|
@@ -188,7 +196,7 @@ | |
| D7CB1413281793F900B24611 /* FruitStoreError.swift in Sources */, | ||
| C71CD66B266C7ACB0038B9CB /* FruitStore.swift in Sources */, | ||
| D7FC4E4C2816F0120093A003 /* Juice.swift in Sources */, | ||
| C73DAF3B255D0CDD00020D38 /* ViewController.swift in Sources */, | ||
| C73DAF3B255D0CDD00020D38 /* JuiceOrderViewController.swift in Sources */, | ||
| C73DAF37255D0CDD00020D38 /* AppDelegate.swift in Sources */, | ||
| C73DAF39255D0CDD00020D38 /* SceneDelegate.swift in Sources */, | ||
| C73DAF4C255D0D0400020D38 /* JuiceMaker.swift in Sources */, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| // | ||
| // JuiceMaker - JuiceOrderViewController.swift | ||
| // Created by 수꿍, 바드. | ||
| // Copyright © yagom academy. All rights reserved. | ||
| // | ||
|
|
||
| import UIKit | ||
|
|
||
| class JuiceOrderViewController: UIViewController { | ||
| private let juiceMaker = JuiceMaker() | ||
|
|
||
| @IBOutlet private weak var strawberryLabel: UILabel? | ||
| @IBOutlet private weak var bananaLabel: UILabel? | ||
| @IBOutlet private weak var pineappleLabel: UILabel? | ||
| @IBOutlet private weak var kiwiLabel: UILabel? | ||
| @IBOutlet private weak var mangoLabel: UILabel? | ||
|
|
||
| override func viewDidLoad() { | ||
| super.viewDidLoad() | ||
| updateFruitStock() | ||
| } | ||
|
|
||
| private func updateFruitStock() { | ||
| strawberryLabel?.text = String(juiceMaker.fruitStore.fruitWarehouse[.strawberry] ?? 0) | ||
| bananaLabel?.text = String(juiceMaker.fruitStore.fruitWarehouse[.banana] ?? 0) | ||
| pineappleLabel?.text = String(juiceMaker.fruitStore.fruitWarehouse[.pineapple] ?? 0) | ||
| kiwiLabel?.text = String(juiceMaker.fruitStore.fruitWarehouse[.kiwi] ?? 0) | ||
| mangoLabel?.text = String(juiceMaker.fruitStore.fruitWarehouse[.mango] ?? 0) | ||
| } | ||
|
|
||
| @IBAction private func makeJuice(_ sender: UIButton) { | ||
|
|
||
| var juice: Juice { | ||
| switch sender.currentTitle { | ||
| case "딸기쥬스 주문": | ||
| return .strawberry | ||
| case "바나나쥬스 주문": | ||
| return .banana | ||
| case "파인애플쥬스 주문": | ||
| return .pineapple | ||
| case "키위쥬스 주문": | ||
| return .kiwi | ||
| case "딸바쥬스 주문": | ||
| return .strawberryBanana | ||
| case "망고쥬스 주문": | ||
| return .mango | ||
| case "망키쥬스 주문": | ||
| return .mangoKiwi | ||
| default: | ||
| return .unknownFruit | ||
| } | ||
| } | ||
|
|
||
| tryMaking(juice) | ||
| updateFruitStock() | ||
| } | ||
|
|
||
| private func tryMaking(_ juice: Juice) { | ||
| do { | ||
| try juiceMaker.make(juice) | ||
| showSuccessAlert(juice) | ||
| } catch FruitStoreError.outOfStock { | ||
| showFailAlert() | ||
| } catch { | ||
| print(error.localizedDescription) | ||
| } | ||
| } | ||
|
|
||
| private func showSuccessAlert(_ juice: Juice) { | ||
| let successAlert = UIAlertController(title: "\(juice.name) 쥬스 나왔습니다!\n 맛있게 드세요!", message: nil, preferredStyle: .alert) | ||
|
|
||
| let ok = UIAlertAction(title: "확인", style: .default, handler: nil) | ||
|
|
||
| successAlert.addAction(ok) | ||
| present(successAlert, animated: true) | ||
| } | ||
|
|
||
| private func showFailAlert() { | ||
| let failAlert = UIAlertController(title: "재료가 모자라요.\n 재고를 수정할까요?", message: nil, preferredStyle: .alert) | ||
| let no = UIAlertAction(title: "아니오", style: .cancel) | ||
| let yes = UIAlertAction(title: "예", style: .default) { action in | ||
| self.goToFruitStockViewController() | ||
| } | ||
|
|
||
| failAlert.addAction(no) | ||
| failAlert.addAction(yes) | ||
| present(failAlert, animated: true) | ||
| } | ||
|
|
||
| @IBAction private func navigationRightButtonTapped(_ sender: UIBarButtonItem) { | ||
| goToFruitStockViewController() | ||
| } | ||
|
|
||
| private func goToFruitStockViewController() { | ||
| guard let controller = self.storyboard?.instantiateViewController(withIdentifier: "FruitStockViewController") else { return } | ||
|
|
||
| self.navigationController?.pushViewController(controller, animated: true) | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,4 +11,5 @@ enum Fruit: String { | |
| case pineapple | ||
| case kiwi | ||
| case mango | ||
| case unknownFruit | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,9 +4,8 @@ | |
| // Copyright © yagom academy. All rights reserved. | ||
| // | ||
|
|
||
| // 과일 저장소 타입 | ||
| class FruitStore { | ||
| private var fruitWarehouse: Dictionary<Fruit, Int> = [ | ||
| private(set) var fruitWarehouse: Dictionary<Fruit, Int> = [ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. private(set) 을 사용하셨군요! 멋집니다 👍🏻
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| Fruit.strawberry: InitialFruitStock.stock, | ||
| Fruit.banana: InitialFruitStock.stock, | ||
| Fruit.pineapple: InitialFruitStock.stock, | ||
|
|
@@ -72,6 +71,8 @@ class FruitStore { | |
| case Juice.mangoKiwi: | ||
| try function(Fruit.mango) | ||
| try function(Fruit.kiwi) | ||
| case Juice.unknownFruit: | ||
| try function(Fruit.unknownFruit) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -93,19 +94,21 @@ class FruitStore { | |
| case Juice.mangoKiwi: | ||
| try function(Fruit.mango, CostOfJuiceProduction.mangoInMangoKiwiJuice) | ||
| try function(Fruit.kiwi, CostOfJuiceProduction.kiwiInMangoKiwiJuice) | ||
| case Juice.unknownFruit: | ||
| try function(Fruit.unknownFruit, CostOfJuiceProduction.unknownFruitInUnknownFruitJuice) | ||
| } | ||
| } | ||
|
|
||
| func handle(_ error: Error) { | ||
| func handle(_ error: Error) -> String { | ||
| switch error { | ||
| case FruitStoreError.outOfStock: | ||
| print(FruitStoreError.outOfStock.localizedDescription) | ||
| return FruitStoreError.outOfStock.localizedDescription | ||
| case FruitStoreError.missingProduct: | ||
| print(FruitStoreError.missingProduct.localizedDescription) | ||
| return FruitStoreError.missingProduct.localizedDescription | ||
| case FruitStoreError.invalidAmount: | ||
| print(FruitStoreError.invalidAmount.localizedDescription) | ||
| return FruitStoreError.invalidAmount.localizedDescription | ||
| default: | ||
| print("알 수 없는 오류입니다") | ||
| return "알 수 없는 오류입니다" | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,19 +4,15 @@ | |
| // Copyright © yagom academy. All rights reserved. | ||
| // | ||
|
|
||
| // 쥬스 메이커 타입 | ||
| struct JuiceMaker { | ||
| let fruitStore = FruitStore() | ||
|
|
||
| func make(_ juice: Juice) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 쥬스메이커의 역할은 쥬스를 만들 수 있는지 검사만 하면 되는 걸까요? 🤔
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 쥬스를 만들수 있는지 검사하고 쥬스메이커가 쥬스를 만들어야 하기 때문에 위 코멘트에서 말한 것처럼 다시 함수를 넣어주었습니다! |
||
| do { | ||
| try checkFruitAvailable(for: juice) | ||
| try checkPossibilityOfMaking(juice) | ||
| } catch (let error) { | ||
| fruitStore.handle(error) | ||
| } | ||
| func make(_ juice: Juice) throws { | ||
| try checkFruitAvailable(for: juice) | ||
| try checkPossibilityOfMaking(juice) | ||
| } | ||
|
|
||
|
|
||
| private func checkFruitAvailable(for juice: Juice) throws { | ||
| try fruitStore.goToWarehouse(of: fruitStore.checkFruitKind(_:), juice: juice) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tag를 사용하셨군요! 멋있습니다 👍🏻