From a27b53623ab0816d1017c391ff937703cc106201 Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Sun, 12 Mar 2023 11:46:43 +0900 Subject: [PATCH] feat: init moduleFactory (#371) --- NADA-iOS-forRelease.xcodeproj/project.pbxproj | 16 ++++++++ .../Sources/Factory/ModuleFactory.swift | 28 +++++++++++++ .../Factory/controllerFromStoryBoard.swift | 41 +++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 NADA-iOS-forRelease/Sources/Factory/ModuleFactory.swift create mode 100644 NADA-iOS-forRelease/Sources/Factory/controllerFromStoryBoard.swift diff --git a/NADA-iOS-forRelease.xcodeproj/project.pbxproj b/NADA-iOS-forRelease.xcodeproj/project.pbxproj index 7bdbf38b..0311b1d8 100644 --- a/NADA-iOS-forRelease.xcodeproj/project.pbxproj +++ b/NADA-iOS-forRelease.xcodeproj/project.pbxproj @@ -96,6 +96,8 @@ 77A4D5FC29BD6F4600367B7C /* AroundMeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A4D5FB29BD6F4600367B7C /* AroundMeViewModel.swift */; }; 77A4D5FE29BD6F9500367B7C /* ViewModelType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A4D5FD29BD6F9500367B7C /* ViewModelType.swift */; }; 77A4D60129BD708C00367B7C /* AroundMeResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A4D60029BD708C00367B7C /* AroundMeResponse.swift */; }; + 77A4D60429BD743600367B7C /* ModuleFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A4D60329BD743600367B7C /* ModuleFactory.swift */; }; + 77A4D60629BD747300367B7C /* controllerFromStoryBoard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A4D60529BD747300367B7C /* controllerFromStoryBoard.swift */; }; 77AA68EA273E0EC4009C89B0 /* CardAddInGroupRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77AA68E9273E0EC4009C89B0 /* CardAddInGroupRequest.swift */; }; 77B4E7482990E420006098DC /* Home.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 77B4E7472990E420006098DC /* Home.storyboard */; }; 77B4E74B2990E50E006098DC /* HomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B4E74A2990E50E006098DC /* HomeViewController.swift */; }; @@ -319,6 +321,8 @@ 77A4D5FB29BD6F4600367B7C /* AroundMeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AroundMeViewModel.swift; sourceTree = ""; }; 77A4D5FD29BD6F9500367B7C /* ViewModelType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModelType.swift; sourceTree = ""; }; 77A4D60029BD708C00367B7C /* AroundMeResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AroundMeResponse.swift; sourceTree = ""; }; + 77A4D60329BD743600367B7C /* ModuleFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleFactory.swift; sourceTree = ""; }; + 77A4D60529BD747300367B7C /* controllerFromStoryBoard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = controllerFromStoryBoard.swift; sourceTree = ""; }; 77AA68E9273E0EC4009C89B0 /* CardAddInGroupRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardAddInGroupRequest.swift; sourceTree = ""; }; 77B4E7422990E00B006098DC /* Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; 77B4E7432990E015006098DC /* Beta.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Beta.xcconfig; sourceTree = ""; }; @@ -803,6 +807,15 @@ path = AroundMe; sourceTree = ""; }; + 77A4D60229BD741C00367B7C /* Factory */ = { + isa = PBXGroup; + children = ( + 77A4D60329BD743600367B7C /* ModuleFactory.swift */, + 77A4D60529BD747300367B7C /* controllerFromStoryBoard.swift */, + ); + path = Factory; + sourceTree = ""; + }; 77B4E7462990E415006098DC /* Home */ = { isa = PBXGroup; children = ( @@ -1138,6 +1151,7 @@ F8FC439A26C01EA90033E151 /* Sources */ = { isa = PBXGroup; children = ( + 77A4D60229BD741C00367B7C /* Factory */, F8FC438526C01CDD0033E151 /* AppDelegate.swift */, F8FC438726C01CDD0033E151 /* SceneDelegate.swift */, F8FC439B26C01EC30033E151 /* Cells */, @@ -1660,10 +1674,12 @@ 77A4D60129BD708C00367B7C /* AroundMeResponse.swift in Sources */, 7734D5B82777A8E8004360E4 /* String+Extension.swift in Sources */, 77A4D5FE29BD6F9500367B7C /* ViewModelType.swift in Sources */, + 77A4D60429BD743600367B7C /* ModuleFactory.swift in Sources */, F8C83FC3272FA17B0009DF0D /* URL.swift in Sources */, 392F7FB4274621F1008CDBF5 /* MoreListTableViewCell.swift in Sources */, 77AA68EA273E0EC4009C89B0 /* CardAddInGroupRequest.swift in Sources */, 77A4D5EF29AE269B00367B7C /* AroundMeViewController.swift in Sources */, + 77A4D60629BD747300367B7C /* controllerFromStoryBoard.swift in Sources */, 3936993E274A53E000684420 /* GroupEditViewController.swift in Sources */, F8C83FAE272F99940009DF0D /* MoyaLoggerPlugin.swift in Sources */, F84BAFAD26FDB543004CA335 /* FrontCardCreationCollectionViewCell.swift in Sources */, diff --git a/NADA-iOS-forRelease/Sources/Factory/ModuleFactory.swift b/NADA-iOS-forRelease/Sources/Factory/ModuleFactory.swift new file mode 100644 index 00000000..8f855b3c --- /dev/null +++ b/NADA-iOS-forRelease/Sources/Factory/ModuleFactory.swift @@ -0,0 +1,28 @@ +// +// ModuleFactory.swift +// NADA-iOS-forRelease +// +// Created by Yi Joon Choi on 2023/03/12. +// + +import UIKit + +/* + - 사용법: + 1) ModuelFactoryProtocol에 넘겨야할 VC를 메서드 형태로 정의만 한다. + 2) ModuleFactory를 extension해서 구현해야 할 부분을 직접 작성한다. + controllerFromStoryboard(익스텐션)를 활용해서 인스턴스를 생성한다 + -> storyboard를 사용하지 않으면 가져오지 않고 뷰컨 자체를 가지고 오면 될 것 같다 + 3) 각각 필요한 VC내에서 MoudleFactory를 가지고 뷰컨을 가져오면 끝! + */ + +protocol ModuleFactoryProtocol { + +} + + +final class ModuleFactory: ModuleFactoryProtocol { + static let shared = ModuleFactory() + private init() { } + +} diff --git a/NADA-iOS-forRelease/Sources/Factory/controllerFromStoryBoard.swift b/NADA-iOS-forRelease/Sources/Factory/controllerFromStoryBoard.swift new file mode 100644 index 00000000..94992d9b --- /dev/null +++ b/NADA-iOS-forRelease/Sources/Factory/controllerFromStoryBoard.swift @@ -0,0 +1,41 @@ +// +// controllerFromStoryBoard.swift +// NADA-iOS-forRelease +// +// Created by Yi Joon Choi on 2023/03/12. +// + +import Foundation +import UIKit + +/* + + - Description: + + Module Factory 형태에서 VC들을 간편하게 선언하기 위해 만든 extension 입니다. + 1) 스토리보드를 enum 형으로 안전하게 선언해서, + 2) 자체 className을 활용해 identifier을 선언하고, + 3) instantitateVieController 기본 메서드를 활용해 VC 인스턴스를 생성합니다. + + 다음 메서드는 ModuleFactory에서 사용됩니다. + + */ + +extension UIViewController { + + private class func instantiateControllerInStoryboard(_ storyboard: UIStoryboard, identifier: String) -> T { + return storyboard.instantiateViewController(withIdentifier: identifier) as! T + } + + class func controllerInStoryboard(_ storyboard: UIStoryboard, identifier: String) -> Self { + return instantiateControllerInStoryboard(storyboard, identifier: identifier) + } + + class func controllerInStoryboard(_ storyboard: UIStoryboard) -> Self { + return controllerInStoryboard(storyboard, identifier: className) + } + + class func controllerFromStoryboard(_ storyboard: Storyboards) -> Self { + return controllerInStoryboard(UIStoryboard(name: storyboard.rawValue, bundle: nil), identifier: className) + } +}