Skip to content
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

쥬스메이커 [STEP 2] 제이티, Ari #119

Merged
merged 17 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
68927c4
feat: 쥬스 주문버튼 터치 시 Alret 표시되는 기능 구현
leeari95 Oct 25, 2021
c8f2ac6
feat: 주문 버튼 터치시 재고가 있는 경우와 없는 경우에 대한 기능 구현
HoneyCoding Oct 25, 2021
e083fff
feat: 과일의 재고가 바뀔 때 마다 화면에 반영되도록 기능 구현
leeari95 Oct 25, 2021
293f811
refactor: HIG 지침에 따라 Alert의 선택지 문구 수정
HoneyCoding Oct 26, 2021
a560ab2
refactor: Fruit타입을 FruitStore 내부에서 외부로 이동
leeari95 Oct 26, 2021
57031d7
refactor: JuiceMakerViewController의 UILabel 프로퍼티 이름 수정
HoneyCoding Oct 26, 2021
eb48bef
refactor: JuiceMakerViewController 내부 메서드명 수정
leeari95 Oct 26, 2021
0331594
refactor: JuiceMakerViewController 내부 메소드 순서 변경
HoneyCoding Oct 26, 2021
8edd150
refactor: orderJuiceButtonTapped 메서드 분리 및 리팩토링
leeari95 Oct 26, 2021
b28fab2
chore: 불필요한 주석 제거
HoneyCoding Oct 26, 2021
5d1c1da
chore: mixFruit 메서드 내부에 에러 문구를 수정
leeari95 Oct 26, 2021
f7bb20f
docs: README.md 파일 내용 추가
HoneyCoding Oct 26, 2021
8bfece8
refactor: 문자열을 모아놓은 enum Text 추가 및 숫자를 문자열로 형변환 하는 코드 수정
HoneyCoding Oct 28, 2021
5f09d5c
refactor: Juice 타입 리팩토링 및 Text 타입 이름 수정
leeari95 Oct 28, 2021
d252b60
refactor: Alert 버튼의 타이틀을 따로 Text 타입으로 구현
HoneyCoding Oct 28, 2021
0484cd1
refactor: FruitStore 내부에 전역변수를 enum Const 타입으로 리팩토링
leeari95 Oct 28, 2021
494468c
refactor: JuiceMakerViewController 내부의 showOutOfStockAlert 메소드의 코드 일부…
HoneyCoding Oct 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: orderJuiceButtonTapped 메서드 분리 및 리팩토링
- orderJuiceButtonTapped 메서드 내부에 do-try-catch문을 분리하여 mixFruit 메서드 추가
- text로 하드코딩 되어있던 switch문을 @IBOutlet을 활용하여 개선
  • Loading branch information
leeari95 committed Oct 26, 2021
commit 8edd150fe9b30be00aa735a9cb0df5c6283b14ab
29 changes: 20 additions & 9 deletions JuiceMaker/JuiceMaker/Controller/JuiceMakerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ class JuiceMakerViewController: UIViewController {
@IBOutlet weak var kiwiStockLabel: UILabel!
@IBOutlet weak var mangoStockLabel: UILabel!

@IBOutlet weak var orderStrawberryBananaJuiceButton: UIButton!
@IBOutlet weak var orderMangoKiwiJuiceButton: UIButton!
@IBOutlet weak var orderStrawberryJuiceButton: UIButton!
@IBOutlet weak var orderBananaJuiceButton: UIButton!
@IBOutlet weak var orderPineappleJuiceButton: UIButton!
@IBOutlet weak var orderKiwiJuiceButton: UIButton!
@IBOutlet weak var orderMangoJuiceButton: UIButton!

override func viewDidLoad() {
super.viewDidLoad()
updateFruitLabels()
Expand All @@ -24,29 +32,32 @@ class JuiceMakerViewController: UIViewController {
}

@IBAction func orderJuiceButtonTapped(_ sender: UIButton) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

모든 button 의 action method 를 개별로 구현할 때와 이렇게 하나에 구현할 때의 장단점은 무엇인가요?

let buttonText = sender.titleLabel?.text
let juice: Juice

switch buttonText {
case "딸바쥬스 주문":
switch sender {
case orderStrawberryBananaJuiceButton:
juice = .strawberryBanana
case "망키쥬스 주문":
case orderMangoKiwiJuiceButton:
juice = .mangoKiwi
case "딸기쥬스 주문":
case orderStrawberryJuiceButton:
juice = .strawberry
case "바나나쥬스 주문":
case orderBananaJuiceButton:
juice = .banana
case "파인애플쥬스 주문":
case orderPineappleJuiceButton:
juice = .pineapple
case "키위쥬스 주문":
case orderKiwiJuiceButton:
juice = .kiwi
case "망고쥬스 주문":
case orderMangoJuiceButton:
juice = .mango
default:
showNotificationAlert(message: "잘못된 접근입니다.")
return
}

mixFruit(juice: juice)
}

func mixFruit(juice: Juice) {
do {
try juiceMaker.mixFruit(juice: juice)
showNotificationAlert(message: "\(juice) 쥬스 나왔습니다! 맛있게 드세요!")
Expand Down
15 changes: 11 additions & 4 deletions JuiceMaker/JuiceMaker/View/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19455" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="DCG-dP-Fms">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19162" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="DCG-dP-Fms">
<device id="retina6_1" orientation="landscape" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19454"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19144"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
Expand Down Expand Up @@ -247,6 +247,13 @@
<outlet property="bananaStockLabel" destination="gvk-pA-Lw5" id="I4h-3W-xpD"/>
<outlet property="kiwiStockLabel" destination="FZq-de-TJG" id="yU2-Ay-SC3"/>
<outlet property="mangoStockLabel" destination="3Ce-SU-JeH" id="eXr-g0-l78"/>
<outlet property="orderBananaJuiceButton" destination="y2A-PH-DJY" id="Z1P-yT-7Uy"/>
<outlet property="orderKiwiJuiceButton" destination="wcW-7H-RXw" id="xo3-Gh-Fdj"/>
<outlet property="orderMangoJuiceButton" destination="q6G-4X-bVm" id="9Js-Wt-Mbv"/>
<outlet property="orderMangoKiwiJuiceButton" destination="ngP-kF-Yii" id="Alo-Pn-WkG"/>
<outlet property="orderPineappleJuiceButton" destination="BFb-ka-wGA" id="uxg-V4-joj"/>
<outlet property="orderStrawberryBananaJuiceButton" destination="hrc-2F-fzl" id="Bm2-Gr-yfn"/>
<outlet property="orderStrawberryJuiceButton" destination="avd-o5-3JM" id="tiT-jE-21D"/>
<outlet property="pineappleStockLabel" destination="ccQ-Dk-PuY" id="lFl-eM-TyK"/>
<outlet property="strawberryStockLabel" destination="Qas-vP-td6" id="wPb-it-h37"/>
</connections>
Expand Down Expand Up @@ -276,7 +283,7 @@
<!--재고 추가-->
<scene sceneID="fkG-vv-hpE">
<objects>
<viewController id="Yu1-lM-nqp" customClass="FruitStoreViewController" customModule="JuiceMaker" customModuleProvider="target" sceneMemberID="viewController">
<viewController modalPresentationStyle="currentContext" id="Yu1-lM-nqp" customClass="FruitStoreViewController" customModule="JuiceMaker" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="tKV-4l-Vtc">
<rect key="frame" x="0.0" y="0.0" width="896" height="414"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down Expand Up @@ -431,7 +438,7 @@
<!--Navigation Controller-->
<scene sceneID="cAf-jL-tPK">
<objects>
<navigationController storyboardIdentifier="FruitStoreView" automaticallyAdjustsScrollViewInsets="NO" id="WwV-Td-3Bn" sceneMemberID="viewController">
<navigationController storyboardIdentifier="FruitStoreView" automaticallyAdjustsScrollViewInsets="NO" modalPresentationStyle="currentContext" id="WwV-Td-3Bn" sceneMemberID="viewController">
<toolbarItems/>
<navigationItem key="navigationItem" id="x5k-dG-c9Q"/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="ufw-7J-6hD">
Expand Down