Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
134cd64
config: Main 스토리보드 삭제 및 루트 뷰 설정
jane1choi Feb 6, 2024
bdbc81c
feat: Then 프로토콜 정의
jane1choi Feb 7, 2024
ce7ba43
feat: UIStackView extension 추가
jane1choi Feb 7, 2024
d6781fd
feat: BankViewController 기본 UI 구성
jane1choi Feb 7, 2024
2fdd92b
chore: 시작 뷰컨트롤러 변경
jane1choi Feb 7, 2024
b507518
chore: ViewController 파일 이름 수정
jane1choi Feb 7, 2024
b25f624
feat: Client 모델 추가
suojae Feb 7, 2024
72e834b
feat: BankTask 모델 추가
suojae Feb 7, 2024
d1ced4c
feat: ViewModel 프로토콜 정의
jane1choi Feb 7, 2024
b4b5466
feat: UITableViewCell+ 파일 추가
jane1choi Feb 8, 2024
673aa24
feat: 커스텀 tableViewCell 정의
jane1choi Feb 8, 2024
c547859
feat: 더미데이터를 활용한 테이블 뷰 UI 구성
jane1choi Feb 8, 2024
33b3c4d
feat: TimerHandler 추가
suojae Feb 8, 2024
ddadc9f
chore: TimeUnit 구조체 추가 및 적용
suojae Feb 8, 2024
b60a853
config: 프로젝트 파일 폴더링
jane1choi Feb 8, 2024
e9686ad
feat: Observable 타입 정의
jane1choi Feb 8, 2024
9b1cdd9
feat: BankRepository 정의
jane1choi Feb 8, 2024
ab84765
feat: BankViewModel 추가 및 폴더링
jane1choi Feb 8, 2024
90b816d
feat: 고객 10명 추가 기능 구현
jane1choi Feb 8, 2024
f614f29
feat: 의존성 주입 코드 추가
jane1choi Feb 8, 2024
f6e4a0e
chore: BankTimer 네이밍 변경
suojae Feb 8, 2024
965cd93
chore: Observable 이용한 Timer 데이터 바인딩
suojae Feb 8, 2024
f4fb31f
feat: reset버튼 액션 추가
suojae Feb 8, 2024
e3af0ee
chore: 변수명에서 get 제거
suojae Feb 8, 2024
bb1d7fa
feat: 셀 재사용에 대비한 초기화 및 UI 설정 코드 추가
jane1choi Feb 8, 2024
41c2dd3
feat: 은행 업무 처리 기능 구현
jane1choi Feb 9, 2024
2e69567
fix: 순환 참조 문제 해결
jane1choi Feb 9, 2024
af19f16
chore: life cycle 코드 위치 수정 및 마크 구문 추가
jane1choi Feb 9, 2024
57066b4
chore: 메서드 네이밍 수정
jane1choi Feb 9, 2024
942a16b
feat: 업무중 테이블 뷰 UI 연결 및 마크 구문 추가
jane1choi Feb 9, 2024
27084bc
chore: 자잘한 코드 수정
jane1choi Feb 9, 2024
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
164 changes: 137 additions & 27 deletions BankManagerUIApp/BankManagerUIApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@
objects = {

/* Begin PBXBuildFile section */
08FE43F42B73972500D09BB7 /* Client.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08FE43F32B73972500D09BB7 /* Client.swift */; };
08FE43F62B73977A00D09BB7 /* BankTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08FE43F52B73977A00D09BB7 /* BankTask.swift */; };
08FE43FE2B74611C00D09BB7 /* BankTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08FE43FD2B74611C00D09BB7 /* BankTimer.swift */; };
7796775D2B73AB18007315E8 /* ClientTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7796775C2B73AB18007315E8 /* ClientTableViewCell.swift */; };
7796775F2B73B208007315E8 /* ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7796775E2B73B208007315E8 /* ViewModel.swift */; };
779677632B74575F007315E8 /* UITableViewCell+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 779677622B74575F007315E8 /* UITableViewCell+.swift */; };
77B02E322B7306E900C3D686 /* UIStackView+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B02E312B7306E900C3D686 /* UIStackView+.swift */; };
77B02E342B730AD700C3D686 /* Then.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B02E332B730AD700C3D686 /* Then.swift */; };
77F8FBB52B74AE510085F544 /* Observable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F8FBB42B74AE510085F544 /* Observable.swift */; };
77F8FBB72B74AEEF0085F544 /* BankViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F8FBB62B74AEEF0085F544 /* BankViewModel.swift */; };
77F8FBBA2B74B6A40085F544 /* BankRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F8FBB92B74B6A40085F544 /* BankRepository.swift */; };
C7694E3B259C3E9F0053667F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7694E3A259C3E9F0053667F /* AppDelegate.swift */; };
C7694E3D259C3E9F0053667F /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7694E3C259C3E9F0053667F /* SceneDelegate.swift */; };
C7694E3F259C3E9F0053667F /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7694E3E259C3E9F0053667F /* ViewController.swift */; };
C7694E42259C3E9F0053667F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C7694E40259C3E9F0053667F /* Main.storyboard */; };
C7694E3F259C3E9F0053667F /* BankViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7694E3E259C3E9F0053667F /* BankViewController.swift */; };
C7694E44259C3EA20053667F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C7694E43259C3EA20053667F /* Assets.xcassets */; };
C7694E47259C3EA20053667F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C7694E45259C3EA20053667F /* LaunchScreen.storyboard */; };
C7694E52259C3EA20053667F /* BankManagerUIAppTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7694E51259C3EA20053667F /* BankManagerUIAppTests.swift */; };
C7694E5D259C3EA20053667F /* BankManagerUIAppUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7694E5C259C3EA20053667F /* BankManagerUIAppUITests.swift */; };
C7D65D1E259C81BD005510E0 /* BankManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7D65D1D259C81BD005510E0 /* BankManager.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -36,11 +45,21 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
08FE43F32B73972500D09BB7 /* Client.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Client.swift; sourceTree = "<group>"; };
08FE43F52B73977A00D09BB7 /* BankTask.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BankTask.swift; sourceTree = "<group>"; };
08FE43FD2B74611C00D09BB7 /* BankTimer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BankTimer.swift; sourceTree = "<group>"; };
7796775C2B73AB18007315E8 /* ClientTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientTableViewCell.swift; sourceTree = "<group>"; };
7796775E2B73B208007315E8 /* ViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModel.swift; sourceTree = "<group>"; };
779677622B74575F007315E8 /* UITableViewCell+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITableViewCell+.swift"; sourceTree = "<group>"; };
77B02E312B7306E900C3D686 /* UIStackView+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIStackView+.swift"; sourceTree = "<group>"; };
77B02E332B730AD700C3D686 /* Then.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Then.swift; sourceTree = "<group>"; };
77F8FBB42B74AE510085F544 /* Observable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Observable.swift; sourceTree = "<group>"; };
77F8FBB62B74AEEF0085F544 /* BankViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BankViewModel.swift; sourceTree = "<group>"; };
77F8FBB92B74B6A40085F544 /* BankRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BankRepository.swift; sourceTree = "<group>"; };
C7694E37259C3E9F0053667F /* BankManagerUIApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BankManagerUIApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
C7694E3A259C3E9F0053667F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
C7694E3C259C3E9F0053667F /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
C7694E3E259C3E9F0053667F /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
C7694E41259C3E9F0053667F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
C7694E3E259C3E9F0053667F /* BankViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BankViewController.swift; sourceTree = "<group>"; };
C7694E43259C3EA20053667F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
C7694E46259C3EA20053667F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
C7694E48259C3EA20053667F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand All @@ -50,7 +69,6 @@
C7694E58259C3EA20053667F /* BankManagerUIAppUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = BankManagerUIAppUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
C7694E5C259C3EA20053667F /* BankManagerUIAppUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BankManagerUIAppUITests.swift; sourceTree = "<group>"; };
C7694E5E259C3EA20053667F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C7D65D1D259C81BD005510E0 /* BankManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BankManager.swift; path = ../../BankManager.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -78,6 +96,98 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
77F8FBA92B7469500085F544 /* App */ = {
isa = PBXGroup;
children = (
C7694E3A259C3E9F0053667F /* AppDelegate.swift */,
C7694E3C259C3E9F0053667F /* SceneDelegate.swift */,
);
path = App;
sourceTree = "<group>";
};
77F8FBAA2B7469630085F544 /* Util */ = {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Util 복수로 바꿔주세요.

isa = PBXGroup;
children = (
77F8FBB02B746A460085F544 /* Type */,
77F8FBAD2B74699F0085F544 /* Constant */,
77F8FBAC2B74697E0085F544 /* Protocol */,
77F8FBAB2B74696D0085F544 /* Extension */,
);
path = Util;
sourceTree = "<group>";
};
77F8FBAB2B74696D0085F544 /* Extension */ = {
isa = PBXGroup;
children = (
77B02E312B7306E900C3D686 /* UIStackView+.swift */,
779677622B74575F007315E8 /* UITableViewCell+.swift */,
);
path = Extension;
sourceTree = "<group>";
};
77F8FBAC2B74697E0085F544 /* Protocol */ = {
isa = PBXGroup;
children = (
7796775E2B73B208007315E8 /* ViewModel.swift */,
77B02E332B730AD700C3D686 /* Then.swift */,
);
path = Protocol;
sourceTree = "<group>";
};
77F8FBAD2B74699F0085F544 /* Constant */ = {
isa = PBXGroup;
children = (
08FE43F52B73977A00D09BB7 /* BankTask.swift */,
);
path = Constant;
sourceTree = "<group>";
};
77F8FBAE2B7469CF0085F544 /* Resource */ = {
isa = PBXGroup;
children = (
C7694E43259C3EA20053667F /* Assets.xcassets */,
C7694E45259C3EA20053667F /* LaunchScreen.storyboard */,
C7694E48259C3EA20053667F /* Info.plist */,
);
path = Resource;
sourceTree = "<group>";
};
77F8FBAF2B746A1B0085F544 /* Scene */ = {
isa = PBXGroup;
children = (
77F8FBB12B746A520085F544 /* BankScene */,
);
path = Scene;
sourceTree = "<group>";
};
77F8FBB02B746A460085F544 /* Type */ = {
isa = PBXGroup;
children = (
08FE43F32B73972500D09BB7 /* Client.swift */,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

모델에 있어야할거같습니다.

77F8FBB42B74AE510085F544 /* Observable.swift */,
);
path = Type;
sourceTree = "<group>";
};
77F8FBB12B746A520085F544 /* BankScene */ = {
isa = PBXGroup;
children = (
C7694E3E259C3E9F0053667F /* BankViewController.swift */,
7796775C2B73AB18007315E8 /* ClientTableViewCell.swift */,
08FE43FD2B74611C00D09BB7 /* BankTimer.swift */,
77F8FBB62B74AEEF0085F544 /* BankViewModel.swift */,
);
path = BankScene;
sourceTree = "<group>";
};
77F8FBB82B74B67D0085F544 /* Model */ = {
isa = PBXGroup;
children = (
77F8FBB92B74B6A40085F544 /* BankRepository.swift */,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

모델..이라고 보는게 맞을까요 ? 여러분들이 생각하는 모델은 무엇인가요 ?

);
path = Model;
sourceTree = "<group>";
};
C7694E2E259C3E9F0053667F = {
isa = PBXGroup;
children = (
Expand All @@ -101,14 +211,11 @@
C7694E39259C3E9F0053667F /* BankManagerUIApp */ = {
isa = PBXGroup;
children = (
C7D65D1D259C81BD005510E0 /* BankManager.swift */,
C7694E3A259C3E9F0053667F /* AppDelegate.swift */,
C7694E3C259C3E9F0053667F /* SceneDelegate.swift */,
C7694E3E259C3E9F0053667F /* ViewController.swift */,
C7694E40259C3E9F0053667F /* Main.storyboard */,
C7694E43259C3EA20053667F /* Assets.xcassets */,
C7694E45259C3EA20053667F /* LaunchScreen.storyboard */,
C7694E48259C3EA20053667F /* Info.plist */,
77F8FBA92B7469500085F544 /* App */,
77F8FBAA2B7469630085F544 /* Util */,
77F8FBB82B74B67D0085F544 /* Model */,
77F8FBAF2B746A1B0085F544 /* Scene */,
77F8FBAE2B7469CF0085F544 /* Resource */,
);
path = BankManagerUIApp;
sourceTree = "<group>";
Expand Down Expand Up @@ -236,7 +343,6 @@
files = (
C7694E47259C3EA20053667F /* LaunchScreen.storyboard in Resources */,
C7694E44259C3EA20053667F /* Assets.xcassets in Resources */,
C7694E42259C3E9F0053667F /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -261,10 +367,20 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C7694E3F259C3E9F0053667F /* ViewController.swift in Sources */,
77F8FBB72B74AEEF0085F544 /* BankViewModel.swift in Sources */,
77F8FBBA2B74B6A40085F544 /* BankRepository.swift in Sources */,
C7694E3F259C3E9F0053667F /* BankViewController.swift in Sources */,
7796775F2B73B208007315E8 /* ViewModel.swift in Sources */,
C7694E3B259C3E9F0053667F /* AppDelegate.swift in Sources */,
779677632B74575F007315E8 /* UITableViewCell+.swift in Sources */,
77F8FBB52B74AE510085F544 /* Observable.swift in Sources */,
08FE43F62B73977A00D09BB7 /* BankTask.swift in Sources */,
7796775D2B73AB18007315E8 /* ClientTableViewCell.swift in Sources */,
77B02E322B7306E900C3D686 /* UIStackView+.swift in Sources */,
08FE43FE2B74611C00D09BB7 /* BankTimer.swift in Sources */,
08FE43F42B73972500D09BB7 /* Client.swift in Sources */,
77B02E342B730AD700C3D686 /* Then.swift in Sources */,
C7694E3D259C3E9F0053667F /* SceneDelegate.swift in Sources */,
C7D65D1E259C81BD005510E0 /* BankManager.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -300,14 +416,6 @@
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
C7694E40259C3E9F0053667F /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
C7694E41259C3E9F0053667F /* Base */,
);
name = Main.storyboard;
sourceTree = "<group>";
};
C7694E45259C3EA20053667F /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup;
children = (
Expand Down Expand Up @@ -441,7 +549,8 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = BankManagerUIApp/Info.plist;
DEVELOPMENT_TEAM = VGM28F2FH7;
INFOPLIST_FILE = BankManagerUIApp/Resource/Info.plist;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Resources 가 맞는거 같습니다.

IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -460,7 +569,8 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = BankManagerUIApp/Info.plist;
DEVELOPMENT_TEAM = VGM28F2FH7;
INFOPLIST_FILE = BankManagerUIApp/Resource/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ 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).
guard let _ = (scene as? UIWindowScene) else { return }
guard let windowScene = (scene as? UIWindowScene) else { return }

window = UIWindow(windowScene: windowScene)
window?.rootViewController = BankViewController(viewModel: BankViewModel())
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

BankViewModel 도 따로 만들어서 init 에서 clientNumber 를 받는게 확장성이 더 좋아보입니다.

window?.makeKeyAndVisible()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

무엇을 위해 호출해주어야 하나요 ?

}

func sceneDidDisconnect(_ scene: UIScene) {
Expand Down
32 changes: 0 additions & 32 deletions BankManagerUIApp/BankManagerUIApp/Base.lproj/Main.storyboard

This file was deleted.

26 changes: 26 additions & 0 deletions BankManagerUIApp/BankManagerUIApp/Model/BankRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// BankRepository.swift
// BankManagerUIApp
//
// Created by EUNJU on 2024/02/08.
//

import Foundation

final class BankRepository {

private var clientNumber: Int = 1

func makeClientData(onCompleted: @escaping ([Client]) -> Void) {
let startNumber = clientNumber
var waitingQueue: [Client] = []

(startNumber..<(startNumber + 10)).forEach {
guard let task = BankTask.allCases.randomElement() else { return }
waitingQueue.append(Client(number: $0, bankTask: task))
}

clientNumber += 10
onCompleted(waitingQueue)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
Expand All @@ -43,8 +41,6 @@
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
Expand Down
45 changes: 45 additions & 0 deletions BankManagerUIApp/BankManagerUIApp/Scene/BankScene/BankTimer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// TimerHandler.swift
// BankManagerUIApp
//
// Created by ㅣ on 2/8/24.
//

import Foundation

private struct TimeUnit {
let hours: Int
let minutes: Int
let seconds: Int
}

final class BankTimer {

private var timer = Timer()
private var count = 0
var timeString: ((String) -> Void)?
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

delegate패턴으로 바꾼다면 어떤식으로 바뀔까요 ?


func start() {
timer = Timer.scheduledTimer(timeInterval: 0.001, target: self, selector: #selector(timerCounter), userInfo: nil, repeats: true)
}

func reset() {
timer.invalidate()
timeString?("00:00:00")
}

@objc private func timerCounter() {
count += 1
let time = secondsToHoursMinutesSeconds(seconds: count)
let convertedTimeString = makeTimeString(time)
timeString?(convertedTimeString)
}

private func secondsToHoursMinutesSeconds(seconds: Int) -> TimeUnit {
return TimeUnit.init(hours: (seconds / 3600), minutes: ((seconds % 3600) / 60), seconds: ((seconds % 3600) % 60))
}

private func makeTimeString(_ timeUnit: TimeUnit) -> String {
return String(format: "%02d:%02d:%02d", timeUnit.hours, timeUnit.minutes, timeUnit.seconds)
}
}
Loading