Skip to content

Commit

Permalink
feat: init moduleFactory (TeamNADA#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlwns33 committed Mar 12, 2023
1 parent 2801693 commit a27b536
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
16 changes: 16 additions & 0 deletions NADA-iOS-forRelease.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -319,6 +321,8 @@
77A4D5FB29BD6F4600367B7C /* AroundMeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AroundMeViewModel.swift; sourceTree = "<group>"; };
77A4D5FD29BD6F9500367B7C /* ViewModelType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModelType.swift; sourceTree = "<group>"; };
77A4D60029BD708C00367B7C /* AroundMeResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AroundMeResponse.swift; sourceTree = "<group>"; };
77A4D60329BD743600367B7C /* ModuleFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleFactory.swift; sourceTree = "<group>"; };
77A4D60529BD747300367B7C /* controllerFromStoryBoard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = controllerFromStoryBoard.swift; sourceTree = "<group>"; };
77AA68E9273E0EC4009C89B0 /* CardAddInGroupRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardAddInGroupRequest.swift; sourceTree = "<group>"; };
77B4E7422990E00B006098DC /* Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = "<group>"; };
77B4E7432990E015006098DC /* Beta.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Beta.xcconfig; sourceTree = "<group>"; };
Expand Down Expand Up @@ -803,6 +807,15 @@
path = AroundMe;
sourceTree = "<group>";
};
77A4D60229BD741C00367B7C /* Factory */ = {
isa = PBXGroup;
children = (
77A4D60329BD743600367B7C /* ModuleFactory.swift */,
77A4D60529BD747300367B7C /* controllerFromStoryBoard.swift */,
);
path = Factory;
sourceTree = "<group>";
};
77B4E7462990E415006098DC /* Home */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1138,6 +1151,7 @@
F8FC439A26C01EA90033E151 /* Sources */ = {
isa = PBXGroup;
children = (
77A4D60229BD741C00367B7C /* Factory */,
F8FC438526C01CDD0033E151 /* AppDelegate.swift */,
F8FC438726C01CDD0033E151 /* SceneDelegate.swift */,
F8FC439B26C01EC30033E151 /* Cells */,
Expand Down Expand Up @@ -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 */,
Expand Down
28 changes: 28 additions & 0 deletions NADA-iOS-forRelease/Sources/Factory/ModuleFactory.swift
Original file line number Diff line number Diff line change
@@ -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() { }

}
41 changes: 41 additions & 0 deletions NADA-iOS-forRelease/Sources/Factory/controllerFromStoryBoard.swift
Original file line number Diff line number Diff line change
@@ -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<T: UIViewController>(_ 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)
}
}

0 comments on commit a27b536

Please sign in to comment.