Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
40 changes: 24 additions & 16 deletions MVVM_Calculator/MVVM_Calculator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@
/* Begin PBXBuildFile section */
55A09183250BC44E000FF31A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55A09182250BC44E000FF31A /* AppDelegate.swift */; };
55A09185250BC44E000FF31A /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55A09184250BC44E000FF31A /* SceneDelegate.swift */; };
55A09187250BC44E000FF31A /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55A09186250BC44E000FF31A /* ViewController.swift */; };
55A09187250BC44E000FF31A /* CalculatorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55A09186250BC44E000FF31A /* CalculatorViewController.swift */; };
55A0918A250BC44E000FF31A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 55A09188250BC44E000FF31A /* Main.storyboard */; };
55A0918C250BC44F000FF31A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 55A0918B250BC44F000FF31A /* Assets.xcassets */; };
55A0918F250BC44F000FF31A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 55A0918D250BC44F000FF31A /* LaunchScreen.storyboard */; };
55A0919B250BC6D2000FF31A /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55A0919A250BC6D2000FF31A /* Model.swift */; };
55A0919D250BC796000FF31A /* ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55A0919C250BC796000FF31A /* ViewModel.swift */; };
55A0919F250BCB1A000FF31A /* OperationType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55A0919E250BCB1A000FF31A /* OperationType.swift */; };
55A0919B250BC6D2000FF31A /* CalculatorModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55A0919A250BC6D2000FF31A /* CalculatorModel.swift */; };
55A0919D250BC796000FF31A /* CalculatorViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55A0919C250BC796000FF31A /* CalculatorViewModel.swift */; };
55A0919F250BCB1A000FF31A /* Command.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55A0919E250BCB1A000FF31A /* Command.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
55A0917F250BC44E000FF31A /* MVVM_Calculator.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MVVM_Calculator.app; sourceTree = BUILT_PRODUCTS_DIR; };
55A09182250BC44E000FF31A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
55A09184250BC44E000FF31A /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
55A09186250BC44E000FF31A /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
55A09186250BC44E000FF31A /* CalculatorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalculatorViewController.swift; sourceTree = "<group>"; };
55A09189250BC44E000FF31A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
55A0918B250BC44F000FF31A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
55A0918E250BC44F000FF31A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
55A09190250BC44F000FF31A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
55A0919A250BC6D2000FF31A /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = "<group>"; };
55A0919C250BC796000FF31A /* ViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModel.swift; sourceTree = "<group>"; };
55A0919E250BCB1A000FF31A /* OperationType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OperationType.swift; sourceTree = "<group>"; };
55A0919A250BC6D2000FF31A /* CalculatorModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalculatorModel.swift; sourceTree = "<group>"; };
55A0919C250BC796000FF31A /* CalculatorViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalculatorViewModel.swift; sourceTree = "<group>"; };
55A0919E250BCB1A000FF31A /* Command.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Command.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -43,6 +43,14 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
192940912517957600F6FBEA /* Common */ = {
isa = PBXGroup;
children = (
55A0919E250BCB1A000FF31A /* Command.swift */,
);
path = Common;
sourceTree = "<group>";
};
55A09176250BC44E000FF31A = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -76,6 +84,7 @@
55A09196250BC45F000FF31A /* Source */ = {
isa = PBXGroup;
children = (
192940912517957600F6FBEA /* Common */,
55A09197250BC466000FF31A /* Model */,
55A09199250BC478000FF31A /* View */,
55A09198250BC470000FF31A /* ViewModel */,
Expand All @@ -86,24 +95,23 @@
55A09197250BC466000FF31A /* Model */ = {
isa = PBXGroup;
children = (
55A0919A250BC6D2000FF31A /* Model.swift */,
55A0919E250BCB1A000FF31A /* OperationType.swift */,
55A0919A250BC6D2000FF31A /* CalculatorModel.swift */,
);
path = Model;
sourceTree = "<group>";
};
55A09198250BC470000FF31A /* ViewModel */ = {
isa = PBXGroup;
children = (
55A0919C250BC796000FF31A /* ViewModel.swift */,
55A0919C250BC796000FF31A /* CalculatorViewModel.swift */,
);
path = ViewModel;
sourceTree = "<group>";
};
55A09199250BC478000FF31A /* View */ = {
isa = PBXGroup;
children = (
55A09186250BC44E000FF31A /* ViewController.swift */,
55A09186250BC44E000FF31A /* CalculatorViewController.swift */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -179,12 +187,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
55A0919D250BC796000FF31A /* ViewModel.swift in Sources */,
55A0919F250BCB1A000FF31A /* OperationType.swift in Sources */,
55A09187250BC44E000FF31A /* ViewController.swift in Sources */,
55A0919D250BC796000FF31A /* CalculatorViewModel.swift in Sources */,
55A0919F250BCB1A000FF31A /* Command.swift in Sources */,
55A09187250BC44E000FF31A /* CalculatorViewController.swift in Sources */,
55A09183250BC44E000FF31A /* AppDelegate.swift in Sources */,
55A09185250BC44E000FF31A /* SceneDelegate.swift in Sources */,
55A0919B250BC6D2000FF31A /* Model.swift in Sources */,
55A0919B250BC6D2000FF31A /* CalculatorModel.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
27 changes: 10 additions & 17 deletions MVVM_Calculator/MVVM_Calculator/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,22 @@
import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {



func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
final class AppDelegate: UIResponder, UIApplicationDelegate {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

상속되지 않는 클래스에 대해 final class로 선언하는 것은 성능상 이점이 있습니다.

관련 내용은 검색해보시고, 접근 수준에 대해서 최대한 낮은 수준(private)부터 부여한 후 높여가는 것처럼, 클래스 선언시에도 final class로 선언하여 상속 불가능한 클래스로 만들고, 나중에 해당 클래스를 상속받을 필요가 있을 때 final을 풀어주는 식의 습관을 들이는 것을 추천드립니다.

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
}

// MARK: UISceneSession Lifecycle

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
func application(_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions) -> UISceneConfiguration {
return UISceneConfiguration(name: "Default Configuration",
sessionRole: connectingSceneSession.role)
}

func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
func application(_ application: UIApplication,
didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

불필요한 템플릿은 제거했습니다.

}


}

19 changes: 9 additions & 10 deletions MVVM_Calculator/MVVM_Calculator/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16097" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Ofg-HO-um2">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Ofg-HO-um2">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<!--Calculator View Controller-->
<scene sceneID="BVU-TF-DYT">
<objects>
<viewController storyboardIdentifier="MainID" id="Ofg-HO-um2" customClass="ViewController" customModule="MVVM_Calculator" customModuleProvider="target" sceneMemberID="viewController">
<viewController storyboardIdentifier="MainID" id="Ofg-HO-um2" customClass="CalculatorViewController" customModule="MVVM_Calculator" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="ZZd-j9-B7W">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down Expand Up @@ -258,7 +258,6 @@
<viewLayoutGuide key="safeArea" id="kCh-3d-XsZ"/>
</view>
<connections>
<outlet property="plusButton" destination="DC7-ew-WTU" id="wA7-cj-2YP"/>
<outlet property="presentLabel" destination="Zs9-bH-hIf" id="df3-RK-as3"/>
<outletCollection property="numberButtons" destination="eBZ-cE-0sX" collectionClass="NSMutableArray" id="HeN-H6-ZuX"/>
<outletCollection property="numberButtons" destination="CeM-2z-LcY" collectionClass="NSMutableArray" id="VbP-1C-EG8"/>
Expand All @@ -270,12 +269,12 @@
<outletCollection property="numberButtons" destination="GCf-i1-UTD" collectionClass="NSMutableArray" id="rha-jg-tEJ"/>
<outletCollection property="numberButtons" destination="vGr-XU-PH8" collectionClass="NSMutableArray" id="jnD-NY-IiL"/>
<outletCollection property="numberButtons" destination="0OJ-sm-nZJ" collectionClass="NSMutableArray" id="9bq-Tn-f9j"/>
<outletCollection property="operatorButtons" destination="9xS-of-Qac" collectionClass="NSMutableArray" id="HqH-Y4-kb5"/>
<outletCollection property="operatorButtons" destination="DC7-ew-WTU" collectionClass="NSMutableArray" id="bxq-B7-QSH"/>
<outletCollection property="operatorButtons" destination="Vfj-Em-JmP" collectionClass="NSMutableArray" id="wob-22-tgz"/>
<outletCollection property="operatorButtons" destination="Hxn-oa-OTJ" collectionClass="NSMutableArray" id="Enk-1N-53f"/>
<outletCollection property="operatorButtons" destination="gfi-rE-myr" collectionClass="NSMutableArray" id="AF4-Ke-kZm"/>
<outletCollection property="operatorButtons" destination="5sH-qO-T1K" collectionClass="NSMutableArray" id="wmI-br-wux"/>
<outletCollection property="commandButtons" destination="9xS-of-Qac" collectionClass="NSMutableArray" id="HqH-Y4-kb5"/>
<outletCollection property="commandButtons" destination="DC7-ew-WTU" collectionClass="NSMutableArray" id="bxq-B7-QSH"/>
<outletCollection property="commandButtons" destination="Vfj-Em-JmP" collectionClass="NSMutableArray" id="wob-22-tgz"/>
<outletCollection property="commandButtons" destination="Hxn-oa-OTJ" collectionClass="NSMutableArray" id="Enk-1N-53f"/>
<outletCollection property="commandButtons" destination="gfi-rE-myr" collectionClass="NSMutableArray" id="AF4-Ke-kZm"/>
<outletCollection property="commandButtons" destination="5sH-qO-T1K" collectionClass="NSMutableArray" id="wmI-br-wux"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="gvp-Ws-Cvl" sceneMemberID="firstResponder"/>
Expand Down
44 changes: 12 additions & 32 deletions MVVM_Calculator/MVVM_Calculator/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,26 @@

import UIKit

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?


func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
func scene(_ scene: UIScene, willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions) {
guard let _ = (scene as? UIWindowScene) else { return }
}

func sceneDidDisconnect(_ scene: UIScene) {
// Called as the scene is being released by the system.
// This occurs shortly after the scene enters the background, or when its session is discarded.
// Release any resources associated with this scene that can be re-created the next time the scene connects.
// The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).
let storyboard = UIStoryboard(name: "Main", bundle: nil)
guard let viewController = storyboard.instantiateInitialViewController() as? CalculatorViewController else { return }
viewController.setViewModel(CalculatorViewModel())
window?.rootViewController = viewController
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

뷰모델을 밖에서 넣어주기 위해 씬델리게이트에 이런 코드를 작성했습니다. 뷰모델을 밖에서 생성해서 넣어줬으니 DI를 한 것입니다.

다양한 뷰모델의 구현을 뷰컨트롤러에 넣고 싶다면 뷰모델을 추상화하고, 그것의 구현체를 넣어주면 될 것입니다.

}

func sceneDidBecomeActive(_ scene: UIScene) {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
}
func sceneDidDisconnect(_ scene: UIScene) {}

func sceneWillResignActive(_ scene: UIScene) {
// Called when the scene will move from an active state to an inactive state.
// This may occur due to temporary interruptions (ex. an incoming phone call).
}
func sceneDidBecomeActive(_ scene: UIScene) {}

func sceneWillEnterForeground(_ scene: UIScene) {
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
}

func sceneDidEnterBackground(_ scene: UIScene) {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
}
func sceneWillResignActive(_ scene: UIScene) {}

func sceneWillEnterForeground(_ scene: UIScene) {}

func sceneDidEnterBackground(_ scene: UIScene) {}
}

Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
//
// OperationType.swift
// Command.swift
// MVVM_Calculator
//
// Created by IJ . on 2020/09/12.
// Copyright © 2020 jun. All rights reserved.
//
enum OperationType: String {

enum Command: String {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

result, initialize가 연산자(OperationType)인지 생각해볼 필요가 있습니다. 이들은 연산자가 아니기 때문에 좀 더 넓은 의미의 Command라는 이름으로 바꿨습니다.

case plus = "+"

case minus = "-"

case multiply = "×"

case divide = "÷"

case result = "="

case initialize = "AC"
}
88 changes: 88 additions & 0 deletions MVVM_Calculator/MVVM_Calculator/Source/Model/CalculatorModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// CalculatorModel.swift
// MVVM_Calculator
//
// Created by IJ . on 2020/09/11.
// Copyright © 2020 jun. All rights reserved.
//

protocol CalculatorModelDelegate: class {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

모델에 대한 델리게이트 프로토콜을 선언했습니다. 이 프로토콜을 구현하는 객체는 모델의 이벤트를 받아 적절하게 처리하게 될 것입니다.

func calculatorModelDidChangeNowValue(with value: Int)
}

struct CalculatorModel {
private(set) var beforeValue: Int = 0
private(set) var nowValue: Int = 0 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

기존에 getNowValue()나 getBeforeValue() 같은 메소드가 있었습니다. 이렇게 해줄 필요 없이 private(set) 접근 지정자를 붙여서 밖에서는 접근만 가능하도록 할 수 있습니다.

didSet {
delegate?.calculatorModelDidChangeNowValue(with: nowValue)
}
}

weak var delegate: CalculatorModelDelegate?

private var beforeCommand: Command?
private var hasCommandUpdated: Bool = false
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

기존에는 isOperationCheck 네이밍이었습니다.

  1. be동사가 앞에 오는 Bool 네이밍의 경우 동사는 과거분사 형태를 사용해 줍니다. (isOperationChecked)
  2. 제 생각에는 네이밍이 애매하다고 생각해서, '커맨드가 갱신되었는가'라는 의미를 갖는 hasCommandUpdated로 이름 바꿨습니다.


mutating func setBeforeValue(_ beforeValue: Int) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

이것도 그렇고 다른 set 메소드들에 대해서, 메소드 이름에서 '어떤 것'을 설정하는지 나타내고 있었으나 인자 레이블에서 이를 한번 더 언급하고 있었습니다. (setBeforeValue(beforeValue:), setNowValue(nowValue:))

이런 경우 인자 레이블을 생략해도 문제 없을 것입니다.

self.beforeValue = beforeValue
}

mutating func setNowValue(_ nowValue: Int){
if hasCommandUpdated {
self.nowValue = nowValue
} else {
self.nowValue = self.nowValue * 10 + nowValue
}

if hasCommandUpdated {
hasCommandUpdated = false
}
}

mutating func setCommand(_ command: String) {
guard let command = Command(rawValue: command) else { return }
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

기존에 if문을 사용했고 else절은 없었습니다. if문을 사용하면 들여쓰기 수준이 하나 높아진 상태로 코드를 작성하게 됩니다. 이런 경우 guard문을 사용하면 코드를 좀 더 읽기 쉽게 할 수 있습니다.


switch command {
case .plus:
performOperatorCommand(.plus)
case .divide:
performOperatorCommand(.divide)
case .minus:
performOperatorCommand(.minus)
case .multiply:
performOperatorCommand(.multiply)
case .result:
guard let beforeCommand = beforeCommand else { return }

switch beforeCommand {
case .plus:
nowValue = beforeValue + nowValue
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

기존에 self가 다 붙어있었습니다.

self를 사용하는 것에 대해 일관된 컨벤션을 갖는 것을 추천합니다.
사용하지 않는 것을 컨벤션으로 둔다면, 프로퍼티의 이름과 겹치거나, escaping closure 내에서 self를 명시적으로 참조할 때만 self를 사용하게 될 것이니 self가 사용된 경우 어떤 컨텍스트에 있는지 알기 쉽게 될 것입니다.

사용하는 것을 컨벤션으로 해도 문제 없습니다. 일관된 컨벤션을 가지기만 하면 됩니다.

case .divide:
nowValue = beforeValue / nowValue
case .minus:
nowValue = beforeValue - nowValue
case .multiply:
nowValue = beforeValue * nowValue
default:
print("4칙연산 이외의 케이스 감지 ERROR")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Command에 연산자도 포함되어 있어서 발생하는 문제라고 생각합니다.

연산자와 기타 커맨드(AC, =)를 구분해서 코드를 작성하면 이런 코드는 나오지 않을 거라 생각합니다.

}
case .initialize:
initialize()
}
}
}

// MARK: - Private Method

private extension CalculatorModel {
mutating func performOperatorCommand(_ command: Command) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

기존 네이밍은 calculate였고, 해당 메소드는 어떤 '계산'을 하고 있지는 않았습니다.

연산자 명령어가 들어왔을 때 어떤 작업을 수행하고 있었으므로 performOperatorCommand 네이밍으로 바꿨습니다.

setBeforeValue(nowValue)
beforeCommand = command
hasCommandUpdated = true
}

mutating func initialize() {
nowValue = 0
beforeValue = 0
}
}
Loading