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: Alert 버튼의 타이틀을 따로 Text 타입으로 구현
  • Loading branch information
HoneyCoding committed Oct 28, 2021
commit d252b6066899f5151138ab7113c017e78fa8d93e
17 changes: 13 additions & 4 deletions JuiceMaker/JuiceMaker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
6B5FDE8C272A761200C04135 /* Text.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B5FDE8B272A761200C04135 /* Text.swift */; };
6B5FDE8C272A761200C04135 /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B5FDE8B272A761200C04135 /* Message.swift */; };
6B5FDEAE272ADC7100C04135 /* Text.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B5FDEAD272ADC7100C04135 /* Text.swift */; };
6BEB79292726956400FF66D4 /* FruitStoreViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BEB79282726956400FF66D4 /* FruitStoreViewController.swift */; };
9A757554271D599A00108EB8 /* RequestError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A757553271D599A00108EB8 /* RequestError.swift */; };
C71CD66B266C7ACB0038B9CB /* FruitStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = C71CD66A266C7ACB0038B9CB /* FruitStore.swift */; };
Expand All @@ -21,7 +22,10 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
6B5FDE8B272A761200C04135 /* Text.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Text.swift; sourceTree = "<group>"; };
6B5FDE8B272A761200C04135 /* Message.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Message.swift; sourceTree = "<group>"; };
6B5FDEAD272ADC7100C04135 /* Text.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Text.swift; sourceTree = "<group>"; };
6B5FDEAF272ADD5E00C04135 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/Main.strings; sourceTree = "<group>"; };
6B5FDEB0272ADD5E00C04135 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/LaunchScreen.strings; sourceTree = "<group>"; };
6BEB79282726956400FF66D4 /* FruitStoreViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FruitStoreViewController.swift; sourceTree = "<group>"; };
9A757553271D599A00108EB8 /* RequestError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestError.swift; sourceTree = "<group>"; };
C71CD66A266C7ACB0038B9CB /* FruitStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FruitStore.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -64,7 +68,8 @@
C73DAF4B255D0D0400020D38 /* JuiceMaker.swift */,
C71CD66A266C7ACB0038B9CB /* FruitStore.swift */,
9A757553271D599A00108EB8 /* RequestError.swift */,
6B5FDE8B272A761200C04135 /* Text.swift */,
6B5FDE8B272A761200C04135 /* Message.swift */,
6B5FDEAD272ADC7100C04135 /* Text.swift */,
);
path = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -147,6 +152,7 @@
knownRegions = (
en,
Base,
ko,
);
mainGroup = C73DAF2A255D0CDC00020D38;
productRefGroup = C73DAF34255D0CDD00020D38 /* Products */;
Expand Down Expand Up @@ -178,8 +184,9 @@
files = (
C71CD66B266C7ACB0038B9CB /* FruitStore.swift in Sources */,
C73DAF3B255D0CDD00020D38 /* JuiceMakerViewController.swift in Sources */,
6B5FDE8C272A761200C04135 /* Text.swift in Sources */,
6B5FDE8C272A761200C04135 /* Message.swift in Sources */,
9A757554271D599A00108EB8 /* RequestError.swift in Sources */,
6B5FDEAE272ADC7100C04135 /* Text.swift in Sources */,
C73DAF37255D0CDD00020D38 /* AppDelegate.swift in Sources */,
C73DAF39255D0CDD00020D38 /* SceneDelegate.swift in Sources */,
C73DAF4C255D0D0400020D38 /* JuiceMaker.swift in Sources */,
Expand All @@ -194,6 +201,7 @@
isa = PBXVariantGroup;
children = (
C73DAF3D255D0CDD00020D38 /* Base */,
6B5FDEAF272ADD5E00C04135 /* ko */,
);
name = Main.storyboard;
sourceTree = "<group>";
Expand All @@ -202,6 +210,7 @@
isa = PBXVariantGroup;
children = (
C73DAF42255D0CDF00020D38 /* Base */,
6B5FDEB0272ADD5E00C04135 /* ko */,
);
name = LaunchScreen.storyboard;
sourceTree = "<group>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class JuiceMakerViewController: UIViewController {
func currentStockLabelUpdate(fruit: Fruit, label: UILabel) {
do {
let stock = try FruitStore.shared.stock(fruit: fruit)
label.Message = stock.description
label.text = stock.description
} catch let error as RequestError {
showNotificationAlert(message: error.errorDescription)
} catch {
Expand All @@ -112,7 +112,7 @@ class JuiceMakerViewController: UIViewController {
}
}

func showNotificationAlert(message: String, title: String = Message.ok.description) {
func showNotificationAlert(message: String, title: String = Text.ok.title) {
let alert = UIAlertController(title: nil, message: message, preferredStyle: .alert)
let cancel = UIAlertAction(title: title, style: .cancel, handler: nil)
alert.addAction(cancel)
Expand All @@ -121,8 +121,8 @@ class JuiceMakerViewController: UIViewController {

func showOutOfStockAlert() {
let alert = UIAlertController(title: nil, message: Message.outOfStock.description, preferredStyle: .alert)
let cancelAction = UIAlertAction(title: Message.cancel.description, style: .cancel, handler: nil)
let okAction = UIAlertAction(title: Message.ok.description, style: .default) { _ in
let cancelAction = UIAlertAction(title: Text.cancel.title, style: .cancel, handler: nil)
let okAction = UIAlertAction(title: Text.ok.title, style: .default) { _ in
guard let viewController = self.storyboard?.instantiateViewController(withIdentifier: "FruitStoreView") else { return }

Choose a reason for hiding this comment

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

  • 재고 화면 view controller 는 왜 이름이 FruitStoreview 인가요?
  • 해당 함수를 따로 빼면 어떤가요?

Copy link
Member Author

Choose a reason for hiding this comment

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

해당 부분도 피드백 반영하여 개선해보았습니다 😄
오늘 시간내서 코드리뷰 해주셔서 정말 감사합니다! 많은 도움이 되었어요!!!!! 😊🙏🏻

self.present(viewController, animated: true, completion: nil)
}
Expand Down
25 changes: 25 additions & 0 deletions JuiceMaker/JuiceMaker/Model/Message.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Text.swift
// JuiceMaker
//
// Created by 김진태 on 2021/10/28.
//

import Foundation

enum Message: CustomStringConvertible {
case juiceFinish(juice: Juice)
case unknownError
case outOfStock

var description: String {
switch self {
case .juiceFinish(let juice):
return "\(juice.name) 쥬스 나왔습니다! 맛있게 드세요!"
case .unknownError:
return "알 수 없는 에러가 발생했습니다."
case .outOfStock:
return "재료가 모자라요. 재고를 수정할까요?"
}
}
}
25 changes: 13 additions & 12 deletions JuiceMaker/JuiceMaker/Model/Text.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,28 @@
// Created by 김진태 on 2021/10/28.
//

import Foundation
import UIKit.UIButton

enum Message: CustomStringConvertible {
case juiceFinish(juice: Juice)
case unknownError
case outOfStock
enum Text {
case cancel
case ok

var description: String {
var title: String {
return localizedTitle(key: self.key)
}

private var key: String {
switch self {
case .juiceFinish(let juice):
return "\(juice.name) 쥬스 나왔습니다! 맛있게 드세요!"
case .unknownError:
return "알 수 없는 에러가 발생했습니다."
case .outOfStock:
return "재료가 모자라요. 재고를 수정할까요?"
case .cancel:
return "Cancel"
case .ok:
return "OK"
}
}

private func localizedTitle(key: String) -> String {
let bundle = Bundle.init(for: UIButton.self)
let title = bundle.localizedString(forKey: key, value: nil, table: nil)
return title
}
Comment on lines +27 to +31

Choose a reason for hiding this comment

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

이 메소드는 무슨 역할을 하나요?

Choose a reason for hiding this comment

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

Apple에서 제공하는 다국어 지원 String을 사용하고자 해당 메소드를 구현했습니다!

  • 해당 메소드를 사용하는 방법은 key-value 방식으로, 특정 키를 제공하면 해당 키에 맞는 title이 나오게 됩니다. 이 title은 localizing이 된 텍스트입니다.
  • 예를 들어 localizedTitle(key: "Cancel") 코드가 실행되면 현재 기기의 언어가 영어로 설정되었을 때에는 "Cancel", 한국어로 설정되었을 때에는 "취소"를 리턴해줍니다.
  • 한국어를 지원하기 위해 프로젝트의 Localization에 Korean을 추가해 주었습니다. 추가해주지 않으면 언어가 영어에서 한국어로 변경되어도 해당 사항이 적용되지 않습니다.
  • Apple에서 제공하는 다국어 지원 String을 사용하기 위해 Bundle의 initialilzer를 사용했습니다. Bundle이 Directory를 추상화한 개념으로 알고 있는데, 아직 Bundle의 구체적인 의미는 확인하지 못했습니다. 혹시 해당 사항 관련해서 Bundle의 구체적인 개념이 어떤 건지 여쭈어볼 수 있을까요?

Choose a reason for hiding this comment

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

NotificationCenter를 사용하지 않고 해당 기능을 구현한 것으로 인해 앱을 실행한 뒤, 기기의 언어를 변경하고 앱에 다시 돌아가면 언어가 제대로 변경되지 않는 현상이 발생할 수 있는지도 궁금합니다!

}
4 changes: 2 additions & 2 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="19162" 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="19455" 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="19144"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19454"/>
<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
3 changes: 3 additions & 0 deletions JuiceMaker/JuiceMaker/View/ko.lproj/Main.strings
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
/* Class = "UILabel"; text = "0"; ObjectID = "FZq-de-TJG"; */
"FZq-de-TJG.text" = "0";

/* Class = "UINavigationItem"; title = "재고 추가"; ObjectID = "Go1-KF-fC4"; */
"Go1-KF-fC4.title" = "재고 추가";

/* Class = "UILabel"; text = "0"; ObjectID = "MpT-VW-hCb"; */
"MpT-VW-hCb.text" = "0";

Expand Down