From dea21cf0ccac204c7f1db4f91c03fa625660af47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B2=E1=84=89=E1=85=A5=E1=84=85=E1=85=B5?= =?UTF-8?q?=E1=86=AB?= Date: Thu, 17 Nov 2022 00:51:51 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=94=A8=20[[Refactor]=20#6=20-=20?= =?UTF-8?q?=ED=8F=B4=EB=8D=94=20=EA=B5=AC=EC=A1=B0=20=EB=A6=AC=ED=8E=99?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Kakao_MVVM.xcodeproj/project.pbxproj | 82 +++++++++------- .../xcshareddata/swiftpm/Package.resolved | 20 +++- .../Application/SceneDelegate.swift | 35 +++---- .../Global/Extensions/Extensions +.swift | 39 -------- .../Kakao_MVVM/Global/Extensions/Int +.swift | 8 ++ .../Global/Extensions/NSObject +.swift | 17 ++++ .../Global/Extensions/UIButton +.swift | 19 ++++ .../Extensions/UICollectionView +.swift | 32 ++++-- .../Global/Extensions/UITableView +.swift | 23 +++-- .../Global/NameSpace/ImageName.swift | 62 ++++++++++++ .../Global/Resources/Main.storyboard | 14 +-- Kakao_MVVM/Kakao_MVVM/Model/User.swift | 11 ++- .../ViewController/SignInViewController.swift | 14 +++ .../ViewController/TestViewController.swift | 58 +++++------ .../SignIn/ViewModel/SignInViewModel.swift | 98 +++++++++++++++++-- .../ViewController/SignUpViewController.swift | 31 +++--- .../Auth/SignUp/ViewModel/.gitkeep | 0 .../View/ Cell/ChattingTableViewCell.swift | 5 +- .../Tabbar/Chat/View/ChattingView.swift | 5 +- .../View/Cell/FriendTableViewCell.swift | 4 +- .../ViewController/FriendViewController.swift | 8 +- .../Friend/ViewModel/FriendViewModel.swift | 92 ++++++++--------- .../Tabbar/MainTabBarController.swift | 3 - .../Utils/CustomView/LoginTextField.swift | 5 +- .../Utils/CustomView/ProfileButton.swift | 6 +- .../Utils/NameSpace/ImageName.swift | 31 ------ .../project.pbxproj | 14 +-- .../Model/Chatting.swift | 2 + .../Resource/SceneDelegate.swift | 4 - .../Storybaords/Base.lproj/Main.storyboard | 33 ------- .../Friend/Cell/FriendTableViewCell.swift | 2 +- .../Friend/FriendViewController.swift | 14 +-- .../Other/Auth/LoginViewController.swift | 7 +- .../Other/Auth/SignUpViewController.swift | 20 ++-- 34 files changed, 481 insertions(+), 337 deletions(-) delete mode 100644 Kakao_MVVM/Kakao_MVVM/Global/Extensions/Extensions +.swift create mode 100644 Kakao_MVVM/Kakao_MVVM/Global/Extensions/Int +.swift create mode 100644 Kakao_MVVM/Kakao_MVVM/Global/Extensions/NSObject +.swift create mode 100644 Kakao_MVVM/Kakao_MVVM/Global/Extensions/UIButton +.swift create mode 100644 Kakao_MVVM/Kakao_MVVM/Global/NameSpace/ImageName.swift create mode 100644 Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewModel/.gitkeep delete mode 100644 Kakao_MVVM/Kakao_MVVM/Utils/NameSpace/ImageName.swift delete mode 100644 SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/View/Storybaords/Base.lproj/Main.storyboard diff --git a/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.pbxproj b/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.pbxproj index 4b99cb2..d4858e5 100644 --- a/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.pbxproj +++ b/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.pbxproj @@ -7,29 +7,32 @@ objects = { /* Begin PBXBuildFile section */ + 521F1A25291A41710039A477 /* .gitkeep in Resources */ = {isa = PBXBuildFile; fileRef = 521F1A24291A41710039A477 /* .gitkeep */; }; + 521F1A2B291E20720039A477 /* Moya in Frameworks */ = {isa = PBXBuildFile; productRef = 521F1A2A291E20720039A477 /* Moya */; }; 525379C2290276DB00682E0B /* RxCocoa in Frameworks */ = {isa = PBXBuildFile; productRef = 525379C1290276DB00682E0B /* RxCocoa */; }; 525379C4290276DB00682E0B /* RxSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 525379C3290276DB00682E0B /* RxSwift */; }; 525379C7290276E600682E0B /* SwiftyColor in Frameworks */ = {isa = PBXBuildFile; productRef = 525379C6290276E600682E0B /* SwiftyColor */; }; 525379CA290276FA00682E0B /* SnapKit in Frameworks */ = {isa = PBXBuildFile; productRef = 525379C9290276FA00682E0B /* SnapKit */; }; 525379CD2902770B00682E0B /* Then in Frameworks */ = {isa = PBXBuildFile; productRef = 525379CC2902770B00682E0B /* Then */; }; - 525379D02902773C00682E0B /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = 525379CF2902773C00682E0B /* Alamofire */; }; 525379EC29027E0900682E0B /* SignInViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525379EB29027E0900682E0B /* SignInViewController.swift */; }; 525379EE29027E4500682E0B /* SignUpViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525379ED29027E4500682E0B /* SignUpViewController.swift */; }; 525379F029027E7000682E0B /* LoginConfirmViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525379EF29027E7000682E0B /* LoginConfirmViewController.swift */; }; 525379F62902809F00682E0B /* FriendViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525379F52902809F00682E0B /* FriendViewController.swift */; }; 525379FC290280DE00682E0B /* ProfileViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525379FB290280DE00682E0B /* ProfileViewController.swift */; }; 52537A02290284DC00682E0B /* UIView +.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52537A01290284DC00682E0B /* UIView +.swift */; }; - 527D7902290289EC00D8426C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 527D7901290289EC00D8426C /* Main.storyboard */; }; 528B30502902756B00DD376E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 528B304F2902756B00DD376E /* AppDelegate.swift */; }; 528B30522902756B00DD376E /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 528B30512902756B00DD376E /* SceneDelegate.swift */; }; 528B30592902756D00DD376E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 528B30582902756D00DD376E /* Assets.xcassets */; }; 528B305C2902756D00DD376E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 528B305A2902756D00DD376E /* LaunchScreen.storyboard */; }; + 529FE3A3292539D000A8D7AE /* NSObject +.swift in Sources */ = {isa = PBXBuildFile; fileRef = 529FE3A2292539D000A8D7AE /* NSObject +.swift */; }; + 529FE3A5292539EA00A8D7AE /* UIButton +.swift in Sources */ = {isa = PBXBuildFile; fileRef = 529FE3A4292539EA00A8D7AE /* UIButton +.swift */; }; + 529FE3A729253A0500A8D7AE /* Int +.swift in Sources */ = {isa = PBXBuildFile; fileRef = 529FE3A629253A0500A8D7AE /* Int +.swift */; }; + 529FE3A929253D8700A8D7AE /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 529FE3A829253D8700A8D7AE /* Main.storyboard */; }; 52B59C56290A1F5500844BE7 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B59C55290A1F5500844BE7 /* User.swift */; }; 52B59C58290A1F6A00844BE7 /* Chatting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B59C57290A1F6A00844BE7 /* Chatting.swift */; }; 52B59C5C290A1FDF00844BE7 /* ProfileButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B59C5B290A1FDF00844BE7 /* ProfileButton.swift */; }; 52B59C5E290A1FF400844BE7 /* LoginTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B59C5D290A1FF400844BE7 /* LoginTextField.swift */; }; 52B59C60290A204700844BE7 /* ImageName.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B59C5F290A204700844BE7 /* ImageName.swift */; }; - 52B59C62290A206400844BE7 /* Extensions +.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B59C61290A206400844BE7 /* Extensions +.swift */; }; 52B59C64290A206E00844BE7 /* UICollectionView +.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B59C63290A206E00844BE7 /* UICollectionView +.swift */; }; 52B59C66290A207300844BE7 /* UITableView +.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B59C65290A207300844BE7 /* UITableView +.swift */; }; 52B59C68290A20CC00844BE7 /* ConsoleLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B59C67290A20CC00844BE7 /* ConsoleLog.swift */; }; @@ -49,25 +52,28 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 521F1A24291A41710039A477 /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; 525379EB29027E0900682E0B /* SignInViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInViewController.swift; sourceTree = ""; }; 525379ED29027E4500682E0B /* SignUpViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpViewController.swift; sourceTree = ""; }; 525379EF29027E7000682E0B /* LoginConfirmViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginConfirmViewController.swift; sourceTree = ""; }; 525379F52902809F00682E0B /* FriendViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendViewController.swift; sourceTree = ""; }; 525379FB290280DE00682E0B /* ProfileViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileViewController.swift; sourceTree = ""; }; 52537A01290284DC00682E0B /* UIView +.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView +.swift"; sourceTree = ""; }; - 527D7901290289EC00D8426C /* Main.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = ""; }; 528B304C2902756B00DD376E /* Kakao_MVVM.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Kakao_MVVM.app; sourceTree = BUILT_PRODUCTS_DIR; }; 528B304F2902756B00DD376E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 528B30512902756B00DD376E /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 528B30582902756D00DD376E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 528B305B2902756D00DD376E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 528B305D2902756D00DD376E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 529FE3A2292539D000A8D7AE /* NSObject +.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSObject +.swift"; sourceTree = ""; }; + 529FE3A4292539EA00A8D7AE /* UIButton +.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIButton +.swift"; sourceTree = ""; }; + 529FE3A629253A0500A8D7AE /* Int +.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Int +.swift"; sourceTree = ""; }; + 529FE3A829253D8700A8D7AE /* Main.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = ""; }; 52B59C55290A1F5500844BE7 /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = ""; }; 52B59C57290A1F6A00844BE7 /* Chatting.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Chatting.swift; sourceTree = ""; }; 52B59C5B290A1FDF00844BE7 /* ProfileButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileButton.swift; sourceTree = ""; }; 52B59C5D290A1FF400844BE7 /* LoginTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginTextField.swift; sourceTree = ""; }; 52B59C5F290A204700844BE7 /* ImageName.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageName.swift; sourceTree = ""; }; - 52B59C61290A206400844BE7 /* Extensions +.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Extensions +.swift"; sourceTree = ""; }; 52B59C63290A206E00844BE7 /* UICollectionView +.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UICollectionView +.swift"; sourceTree = ""; }; 52B59C65290A207300844BE7 /* UITableView +.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITableView +.swift"; sourceTree = ""; }; 52B59C67290A20CC00844BE7 /* ConsoleLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsoleLog.swift; sourceTree = ""; }; @@ -93,8 +99,8 @@ files = ( 525379CD2902770B00682E0B /* Then in Frameworks */, 525379C4290276DB00682E0B /* RxSwift in Frameworks */, + 521F1A2B291E20720039A477 /* Moya in Frameworks */, 525379CA290276FA00682E0B /* SnapKit in Frameworks */, - 525379D02902773C00682E0B /* Alamofire in Frameworks */, 525379C7290276E600682E0B /* SwiftyColor in Frameworks */, 525379C2290276DB00682E0B /* RxCocoa in Frameworks */, ); @@ -103,6 +109,14 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 521F1A23291A41060039A477 /* ViewModel */ = { + isa = PBXGroup; + children = ( + 521F1A24291A41710039A477 /* .gitkeep */, + ); + path = ViewModel; + sourceTree = ""; + }; 525379D129027A7D00682E0B /* Application */ = { isa = PBXGroup; children = ( @@ -125,7 +139,7 @@ 525379D329027BB800682E0B /* Global */ = { isa = PBXGroup; children = ( - 525379EA29027D2C00682E0B /* Literals */, + 52B59C5A290A1FCF00844BE7 /* NameSpace */, 525379E829027D0600682E0B /* Protocol */, 525379E729027CFD00682E0B /* Resources */, 525379E629027CF200682E0B /* Extensions */, @@ -136,7 +150,6 @@ 525379D429027BC000682E0B /* Utils */ = { isa = PBXGroup; children = ( - 52B59C5A290A1FCF00844BE7 /* NameSpace */, 52B59C59290A1FC700844BE7 /* CustomView */, ); path = Utils; @@ -196,7 +209,7 @@ 525379DA29027C7400682E0B /* SignUp */ = { isa = PBXGroup; children = ( - 52B59C7B290A258800844BE7 /* ViewModel */, + 521F1A23291A41060039A477 /* ViewModel */, 525379DE29027C9500682E0B /* ViewController */, 525379DB29027C8A00682E0B /* View */, ); @@ -267,10 +280,12 @@ 525379E629027CF200682E0B /* Extensions */ = { isa = PBXGroup; children = ( - 52B59C61290A206400844BE7 /* Extensions +.swift */, + 529FE3A629253A0500A8D7AE /* Int +.swift */, 52537A01290284DC00682E0B /* UIView +.swift */, 52B59C65290A207300844BE7 /* UITableView +.swift */, 52B59C63290A206E00844BE7 /* UICollectionView +.swift */, + 529FE3A2292539D000A8D7AE /* NSObject +.swift */, + 529FE3A4292539EA00A8D7AE /* UIButton +.swift */, ); path = Extensions; sourceTree = ""; @@ -278,9 +293,9 @@ 525379E729027CFD00682E0B /* Resources */ = { isa = PBXGroup; children = ( + 529FE3A829253D8700A8D7AE /* Main.storyboard */, 528B305A2902756D00DD376E /* LaunchScreen.storyboard */, 528B30582902756D00DD376E /* Assets.xcassets */, - 527D7901290289EC00D8426C /* Main.storyboard */, 52B59C67290A20CC00844BE7 /* ConsoleLog.swift */, ); path = Resources; @@ -416,6 +431,7 @@ 52B59C5A290A1FCF00844BE7 /* NameSpace */ = { isa = PBXGroup; children = ( + 525379EA29027D2C00682E0B /* Literals */, 52B59C5F290A204700844BE7 /* ImageName.swift */, ); path = NameSpace; @@ -553,13 +569,6 @@ path = ViewController; sourceTree = ""; }; - 52B59C7B290A258800844BE7 /* ViewModel */ = { - isa = PBXGroup; - children = ( - ); - path = ViewModel; - sourceTree = ""; - }; 52B59C7C290A25D500844BE7 /* Cell */ = { isa = PBXGroup; children = ( @@ -598,7 +607,7 @@ 525379C6290276E600682E0B /* SwiftyColor */, 525379C9290276FA00682E0B /* SnapKit */, 525379CC2902770B00682E0B /* Then */, - 525379CF2902773C00682E0B /* Alamofire */, + 521F1A2A291E20720039A477 /* Moya */, ); productName = Kakao_MVVM; productReference = 528B304C2902756B00DD376E /* Kakao_MVVM.app */; @@ -633,7 +642,7 @@ 525379C5290276E600682E0B /* XCRemoteSwiftPackageReference "SwiftyColor" */, 525379C8290276FA00682E0B /* XCRemoteSwiftPackageReference "SnapKit" */, 525379CB2902770B00682E0B /* XCRemoteSwiftPackageReference "Then" */, - 525379CE2902773C00682E0B /* XCRemoteSwiftPackageReference "Alamofire" */, + 521F1A29291E20720039A477 /* XCRemoteSwiftPackageReference "Moya" */, ); productRefGroup = 528B304D2902756B00DD376E /* Products */; projectDirPath = ""; @@ -649,9 +658,10 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 527D7902290289EC00D8426C /* Main.storyboard in Resources */, 528B305C2902756D00DD376E /* LaunchScreen.storyboard in Resources */, 528B30592902756D00DD376E /* Assets.xcassets in Resources */, + 521F1A25291A41710039A477 /* .gitkeep in Resources */, + 529FE3A929253D8700A8D7AE /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -663,7 +673,6 @@ buildActionMask = 2147483647; files = ( 52B59C85290A267400844BE7 /* ChattingView.swift in Sources */, - 52B59C62290A206400844BE7 /* Extensions +.swift in Sources */, 52B59C5C290A1FDF00844BE7 /* ProfileButton.swift in Sources */, 52B59C6A290A21CD00844BE7 /* MainTabBarController.swift in Sources */, 52B59C68290A20CC00844BE7 /* ConsoleLog.swift in Sources */, @@ -678,6 +687,8 @@ 52B59C58290A1F6A00844BE7 /* Chatting.swift in Sources */, 528B30502902756B00DD376E /* AppDelegate.swift in Sources */, 528B30522902756B00DD376E /* SceneDelegate.swift in Sources */, + 529FE3A5292539EA00A8D7AE /* UIButton +.swift in Sources */, + 529FE3A3292539D000A8D7AE /* NSObject +.swift in Sources */, 525379FC290280DE00682E0B /* ProfileViewController.swift in Sources */, 52F42F39290A86E4005680BC /* FriendViewModel.swift in Sources */, 52B59C87290A267D00844BE7 /* OpenChattingView.swift in Sources */, @@ -686,6 +697,7 @@ 525379EC29027E0900682E0B /* SignInViewController.swift in Sources */, 52B59C8B290A26B300844BE7 /* FeedViewController.swift in Sources */, 52537A02290284DC00682E0B /* UIView +.swift in Sources */, + 529FE3A729253A0500A8D7AE /* Int +.swift in Sources */, 52B59C56290A1F5500844BE7 /* User.swift in Sources */, 52F42F3B290AA645005680BC /* SignInViewModel.swift in Sources */, 52B59C7E290A260400844BE7 /* FriendTableViewCell.swift in Sources */, @@ -903,6 +915,14 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ + 521F1A29291E20720039A477 /* XCRemoteSwiftPackageReference "Moya" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/Moya/Moya"; + requirement = { + branch = master; + kind = branch; + }; + }; 525379C0290276DB00682E0B /* XCRemoteSwiftPackageReference "RxSwift" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/ReactiveX/RxSwift"; @@ -935,17 +955,14 @@ kind = branch; }; }; - 525379CE2902773C00682E0B /* XCRemoteSwiftPackageReference "Alamofire" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/Alamofire/Alamofire.git"; - requirement = { - branch = master; - kind = branch; - }; - }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ + 521F1A2A291E20720039A477 /* Moya */ = { + isa = XCSwiftPackageProductDependency; + package = 521F1A29291E20720039A477 /* XCRemoteSwiftPackageReference "Moya" */; + productName = Moya; + }; 525379C1290276DB00682E0B /* RxCocoa */ = { isa = XCSwiftPackageProductDependency; package = 525379C0290276DB00682E0B /* XCRemoteSwiftPackageReference "RxSwift" */; @@ -971,11 +988,6 @@ package = 525379CB2902770B00682E0B /* XCRemoteSwiftPackageReference "Then" */; productName = Then; }; - 525379CF2902773C00682E0B /* Alamofire */ = { - isa = XCSwiftPackageProductDependency; - package = 525379CE2902773C00682E0B /* XCRemoteSwiftPackageReference "Alamofire" */; - productName = Alamofire; - }; /* End XCSwiftPackageProductDependency section */ }; rootObject = 528B30442902756B00DD376E /* Project object */; diff --git a/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 41568b3..1414830 100644 --- a/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -4,9 +4,27 @@ "identity" : "alamofire", "kind" : "remoteSourceControl", "location" : "https://github.com/Alamofire/Alamofire.git", + "state" : { + "revision" : "8dd85aee02e39dd280c75eef88ffdb86eed4b07b", + "version" : "5.6.2" + } + }, + { + "identity" : "moya", + "kind" : "remoteSourceControl", + "location" : "https://github.com/Moya/Moya", "state" : { "branch" : "master", - "revision" : "bdecb2c87a21a236dcfe88b21532ad3f0e3d20f4" + "revision" : "77e67c0b25ebd785c6fe56cad544885f67c8c2c4" + } + }, + { + "identity" : "reactiveswift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/ReactiveCocoa/ReactiveSwift.git", + "state" : { + "revision" : "c43bae3dac73fdd3cb906bd5a1914686ca71ed3c", + "version" : "6.7.0" } }, { diff --git a/Kakao_MVVM/Kakao_MVVM/Application/SceneDelegate.swift b/Kakao_MVVM/Kakao_MVVM/Application/SceneDelegate.swift index b478e68..5702753 100644 --- a/Kakao_MVVM/Kakao_MVVM/Application/SceneDelegate.swift +++ b/Kakao_MVVM/Kakao_MVVM/Application/SceneDelegate.swift @@ -11,29 +11,24 @@ 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 _ = (scene as? UIWindowScene) else { return } + if let windowScene = scene as? UIWindowScene { + + let window = UIWindow(windowScene: windowScene) + window.overrideUserInterfaceStyle = UIUserInterfaceStyle.light + +// let rootVC = FriendViewController() +// let navigationController = UINavigationController(rootViewController: rootVC) - if let windowScene = scene as? UIWindowScene { - - let window = UIWindow(windowScene: windowScene) - window.overrideUserInterfaceStyle = UIUserInterfaceStyle.light - - let rootVC = FriendViewController() - let navigationController = UINavigationController(rootViewController: rootVC) - - let mainVC = MainTabBarController() - - window.rootViewController = mainVC - window.makeKeyAndVisible() - self.window = window - } + let mainVC = MainTabBarController() + window.rootViewController = mainVC + window.makeKeyAndVisible() + self.window = window } - + } 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. diff --git a/Kakao_MVVM/Kakao_MVVM/Global/Extensions/Extensions +.swift b/Kakao_MVVM/Kakao_MVVM/Global/Extensions/Extensions +.swift deleted file mode 100644 index 49f5ac9..0000000 --- a/Kakao_MVVM/Kakao_MVVM/Global/Extensions/Extensions +.swift +++ /dev/null @@ -1,39 +0,0 @@ -// -// Extensions +.swift -// Kakao_MVVM -// -// Created by Mac Book Pro on 2022/10/27. -// - -import Foundation -import UIKit - -protocol ReusableView: AnyObject { -} - -extension ReusableView where Self: UIView { - static var identifier: String { - return String(describing: self) - } -} - - -extension UIButton { - public func configureButton(title : String){ - self.setTitle(title, for: .normal) - self.setTitleColor(.black, for: .normal) - self.titleLabel?.textAlignment = .center - self.backgroundColor = .systemGray6 - self.layer.cornerRadius = 5 - } -} - -extension Int { - public var color: UIColor { - let red = CGFloat(self as Int >> 16 & 0xff) / 255 - let green = CGFloat(self >> 8 & 0xff) / 255 - let blue = CGFloat(self & 0xff) / 255 - return UIColor(red: red, green: green, blue: blue, alpha: 1) - } -} - diff --git a/Kakao_MVVM/Kakao_MVVM/Global/Extensions/Int +.swift b/Kakao_MVVM/Kakao_MVVM/Global/Extensions/Int +.swift new file mode 100644 index 0000000..e7c92b4 --- /dev/null +++ b/Kakao_MVVM/Kakao_MVVM/Global/Extensions/Int +.swift @@ -0,0 +1,8 @@ +// +// Int +.swift +// Kakao_MVVM +// +// Created by Mac Book Pro on 2022/11/17. +// + +import Foundation diff --git a/Kakao_MVVM/Kakao_MVVM/Global/Extensions/NSObject +.swift b/Kakao_MVVM/Kakao_MVVM/Global/Extensions/NSObject +.swift new file mode 100644 index 0000000..67b8288 --- /dev/null +++ b/Kakao_MVVM/Kakao_MVVM/Global/Extensions/NSObject +.swift @@ -0,0 +1,17 @@ +// +// NSObject +.swift +// Kakao_MVVM +// +// Created by Mac Book Pro on 2022/11/17. +// + +import Foundation + +extension NSObject { + static var className: String { + NSStringFromClass(self.classForCoder()).components(separatedBy: ".").last! + } + var className: String { + NSStringFromClass(self.classForCoder).components(separatedBy: ".").last! + } + } diff --git a/Kakao_MVVM/Kakao_MVVM/Global/Extensions/UIButton +.swift b/Kakao_MVVM/Kakao_MVVM/Global/Extensions/UIButton +.swift new file mode 100644 index 0000000..849bed1 --- /dev/null +++ b/Kakao_MVVM/Kakao_MVVM/Global/Extensions/UIButton +.swift @@ -0,0 +1,19 @@ +// +// UIButton +.swift +// Kakao_MVVM +// +// Created by Mac Book Pro on 2022/11/17. +// + +import Foundation +import UIKit + +extension UIButton { + public func configureButton(title : String){ + self.setTitle(title, for: .normal) + self.setTitleColor(.black, for: .normal) + self.titleLabel?.textAlignment = .center + self.backgroundColor = .systemGray6 + self.layer.cornerRadius = 5 + } +} diff --git a/Kakao_MVVM/Kakao_MVVM/Global/Extensions/UICollectionView +.swift b/Kakao_MVVM/Kakao_MVVM/Global/Extensions/UICollectionView +.swift index d6c568d..4dcc38c 100644 --- a/Kakao_MVVM/Kakao_MVVM/Global/Extensions/UICollectionView +.swift +++ b/Kakao_MVVM/Kakao_MVVM/Global/Extensions/UICollectionView +.swift @@ -8,12 +8,30 @@ import Foundation import UIKit -extension UICollectionViewCell: ReusableView {} +//extension UICollectionViewCell: ReusableView {} +// +//extension UICollectionView{ +// func register(_ cellClass: T.Type){ +// let identifier = T.identifier +// self.register(T.self, forCellWithReuseIdentifier: identifier) +// } +//} + -extension UICollectionView{ - func register(_ cellClass: T.Type){ - let identifier = T.identifier - self.register(T.self, forCellWithReuseIdentifier: identifier) - } -} +protocol UICollectionViewRegisterable { + static var isFromNib: Bool { get } + static func register(target: UITableView) + } + extension UICollectionViewRegisterable where Self: UICollectionViewCell { + static func register(target: UICollectionView) { + target.register(Self.self, forCellWithReuseIdentifier: Self.className) + /* + if self.isFromNib { + target.register(UINib(nibName: Self.className, bundle: nil), forCellWithReuseIdentifier: Self.className) + } else { + target.register(Self.self, forCellWithReuseIdentifier: Self.className) + } + */ + } + } diff --git a/Kakao_MVVM/Kakao_MVVM/Global/Extensions/UITableView +.swift b/Kakao_MVVM/Kakao_MVVM/Global/Extensions/UITableView +.swift index 09b841c..3f17207 100644 --- a/Kakao_MVVM/Kakao_MVVM/Global/Extensions/UITableView +.swift +++ b/Kakao_MVVM/Kakao_MVVM/Global/Extensions/UITableView +.swift @@ -8,12 +8,21 @@ import Foundation import UIKit -extension UITableViewCell: ReusableView {} -extension UITableView{ - func register(_ cellClass: T.Type){ - let identifier = T.identifier - self.register(T.self, forCellReuseIdentifier: identifier) - } -} +protocol UITableViewRegisterable { + static var isFromNib: Bool { get } + static func register(target: UITableView) + } + extension UITableViewRegisterable where Self: UITableViewCell { + static func register(target: UITableView) { + target.register(Self.self, forCellReuseIdentifier: Self.className) + /* + if self.isFromNib { + target.register(UINib(nibName: Self.className, bundle: nil), forCellReuseIdentifier: Self.className) + } else { + target.register(Self.self, forCellReuseIdentifier: Self.className) + } + */ + } + } diff --git a/Kakao_MVVM/Kakao_MVVM/Global/NameSpace/ImageName.swift b/Kakao_MVVM/Kakao_MVVM/Global/NameSpace/ImageName.swift new file mode 100644 index 0000000..bc393cf --- /dev/null +++ b/Kakao_MVVM/Kakao_MVVM/Global/NameSpace/ImageName.swift @@ -0,0 +1,62 @@ +// +// ImageName.swift +// SOPT-Assignment-KAKAO +// +// Created by Mac Book Pro on 2022/10/24. +// + +import UIKit + +public enum Image{ + public static let defaultProfileImage = UIImage(named: "profileImage") + public static let profileMessageButtonImg = UIImage(systemName: "message.fill") + public static let profileStoryButtonImg = UIImage(named: "profileStoryImg") + public static let profileEditButtonImg = UIImage(named: "profileEditImg") + + public static let settingButtonImage = UIImage(systemName: "gearshape") + public static let plusButtonImage = UIImage(systemName: "plus") + public static let closeButtonImage = UIImage(systemName: "xmark") + + + public static let chattingBannerImg = UIImage(named: "chattingBannerImg") + public static let profileImg = [ + UIImage(named: "profileImage1"), + UIImage(named: "profileImage2"), + UIImage(named: "profileImage3"), + UIImage(named: "profileImage4"), + UIImage(named: "profileImage5"), + UIImage(named: "profileImage6"), + UIImage(named: "profileImage7"), + UIImage(named: "profileImage8"), + UIImage(named: "profileImage9"), + ] + + + public static let selectPhotoImage = UIImage(systemName: "camera.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: 15)) + public static let defaultPhotoImage = UIImage(systemName: "photo.fill") + public static let photoImage = [ + UIImage(named: "galleryImage1"), + UIImage(named: "galleryImage2"), + UIImage(named: "galleryImage3"), + UIImage(named: "galleryImage4"), + UIImage(named: "galleryImage5"), + UIImage(named: "galleryImage6"), + UIImage(named: "galleryImage7"), + UIImage(named: "galleryImage8"), + UIImage(named: "galleryImage9"), + UIImage(named: "galleryImage10"), + UIImage(named: "galleryImage11"), + UIImage(named: "galleryImage12"), + UIImage(named: "galleryImage13"), + UIImage(named: "galleryImage14"), + UIImage(named: "galleryImage15"), + UIImage(named: "galleryImage16"), + UIImage(named: "galleryImage17"), + UIImage(named: "galleryImage18"), + UIImage(named: "galleryImage19"), + UIImage(named: "galleryImage20"), + UIImage(named: "galleryImage21"), + UIImage(named: "galleryImage22"), + UIImage(named: "galleryImage23") + ] +} diff --git a/Kakao_MVVM/Kakao_MVVM/Global/Resources/Main.storyboard b/Kakao_MVVM/Kakao_MVVM/Global/Resources/Main.storyboard index 10a7ba1..cdffe9f 100644 --- a/Kakao_MVVM/Kakao_MVVM/Global/Resources/Main.storyboard +++ b/Kakao_MVVM/Kakao_MVVM/Global/Resources/Main.storyboard @@ -1,19 +1,19 @@ - - + + - + - + - + - + @@ -21,7 +21,7 @@ - + diff --git a/Kakao_MVVM/Kakao_MVVM/Model/User.swift b/Kakao_MVVM/Kakao_MVVM/Model/User.swift index 17e3277..76ae856 100644 --- a/Kakao_MVVM/Kakao_MVVM/Model/User.swift +++ b/Kakao_MVVM/Kakao_MVVM/Model/User.swift @@ -13,11 +13,18 @@ struct User{ var profileImg : UIImage var stateMessage : String - - init(name : String, profileImg: UIImage = Image.defaultProfileImage!, stateMessage: String = ""){ + init(name : String, profileImg: UIImage, stateMessage: String){ self.name = name self.profileImg = profileImg self.stateMessage = stateMessage } + init(name: String){ + self.name = name + self.profileImg = Image.defaultProfileImage! + self.stateMessage = "" +// self.init(name: name, profileImg: Image.defaultProfileImage!, stateMessage: "") + } } + + diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/SignInViewController.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/SignInViewController.swift index c881856..72a22b4 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/SignInViewController.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/SignInViewController.swift @@ -7,8 +7,13 @@ import UIKit import Then +import RxSwift +import RxCocoa class SignInViewController: UIViewController { +// private var viewModel = SignInViewModel() + private let disposeBag = DisposeBag() + //MARK: UIView private let startLabel = UILabel().then{ $0.text = "카카오톡을 시작합니다" @@ -50,6 +55,13 @@ class SignInViewController: UIViewController { } } extension SignInViewController{ + private func bindingRx(){ +// emailTextField.rx.text +// .orEmpty +// .bind(to: idValue) + } + + private func setLoginViewControllerLayout(){ [startLabel, explainLabel, emailTextField, passwordTextField, loginButton, signUpButton, findAccountLabel].forEach { view.addSubview($0 as! UIView) @@ -106,3 +118,5 @@ extension SignInViewController : LoginConfirmViewControllerDelegate{ self.navigationController?.dismiss(animated: true) } } + + diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/TestViewController.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/TestViewController.swift index 4b5cf2f..1f57cbf 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/TestViewController.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/TestViewController.swift @@ -1,32 +1,32 @@ +//// +//// TestViewController.swift +//// Kakao_MVVM +//// +//// Created by Mac Book Pro on 2022/10/27. +//// // -// TestViewController.swift -// Kakao_MVVM +//import UIKit +//import RxSwift // -// Created by Mac Book Pro on 2022/10/27. +//class TestViewController: UIViewController { +// let viewModel: SignInViewModel +// var disposeBag = DisposeBag() +// +// override func viewDidLoad() { +// super.viewDidLoad() // - -import UIKit -import RxSwift - -class TestViewController: UIViewController { - let viewModel: SignInViewModel - var disposeBag = DisposeBag() - - override func viewDidLoad() { - super.viewDidLoad() - - setupBindings() - } - - init(viewModel: SignInViewModel = SignInViewModel()) { - self.viewModel = viewModel - super.init(nibName: nil, bundle: nil) - } - required init?(coder aDecoder: NSCoder) { - viewModel = SignInViewModel() - super.init(coder: aDecoder) - } - - func setupBindings() { - } -} +// setupBindings() +// } +// +// init(viewModel: SignInViewModel = SignInViewModel()) { +// self.viewModel = viewModel +// super.init(nibName: nil, bundle: nil) +// } +// required init?(coder aDecoder: NSCoder) { +//// viewModel = SignInViewModel() +// super.init(coder: aDecoder) +// } +// +// func setupBindings() { +// } +//} diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewModel/SignInViewModel.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewModel/SignInViewModel.swift index f0390d0..cdee3e1 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewModel/SignInViewModel.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewModel/SignInViewModel.swift @@ -6,20 +6,100 @@ // import Foundation +import RxCocoa import RxSwift struct SignInViewModel{ - var name : Observable + let disposeBag = DisposeBag() + + //MARK: - INPUT + let userLogin: AnyObserver - func login(name: String) -> Observable { - return Observable.create({ (observer) -> Disposable in + //MARK: - OUTPUT + let loginedUser: Observable + + init(loginModel: LoginModel = LoginModel()) { + let login = PublishSubject() + userLogin = login.asObserver() + + } +} - print("\(observer)") // 요기다가 비지니스 로직 (네트워크를 타고 온 것들) - - observer.onNext(name) - - return Disposables.create() - }) +struct LoginModel{ + func loginUser (email: String)-> Observable { + return Observable.create { observer in + observer.onNext(User(name: email)) + return Disposables.create() } + } +} + +/* +struct SignInViewModel{ + var name : Observable + var loginUser: PublishSubject = PublishSubject() + var loginBtnTouched: PublishRelay = PublishRelay() + + var idValue: PublishRelay = PublishRelay() + var pwValue: PublishRelay = PublishRelay() + + // loginInfo 는 Observable !!!!! -> 위 값들을 합친!!!!! + var loginInfo:Observable { + // subject 들의 값을 합칠 수 있음! + return Observable.combineLatest(idValue, pwValue) { id, pw in + return id ?? "" + } + } + + + let disposeBag = DisposeBag() + + + +// 우선 여기까지 + init(model:Login = Login()) { + loginBtnTouched.withLatestFrom(loginInfo).flatMapLatest{ + return model.login(email: $0).materialize() + }.subscribe(onNext: { [unowned self] (event) in + switch event { + case .next(let user): + self.loginUser.onNext(user) + case .error(let error): + self.loginUser.onNext(nil) + case .completed: + print("COMPLTED") + } + }).disposed(by: disposeBag) + } + +} + +struct Login{ + func login(email: String) -> Observable { + return Observable.create({ (observer) -> Disposable in + + print("\(observer)") // 요기다가 비지니스 로직 (네트워크를 타고 온 것들) + + observer.onNext(email) + + return Disposables.create() + + }) + } +} +// 로직 전용 Model 에서 하는 코드 +/* +func login(name: String) -> Observable { + return Observable.create({ (observer) -> Disposable in + + print("\(observer)") // 요기다가 비지니스 로직 (네트워크를 타고 온 것들) + + observer.onNext(name) + + return Disposables.create() + + }) } + */ +*/ diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewController/SignUpViewController.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewController/SignUpViewController.swift index 5750673..00914d1 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewController/SignUpViewController.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewController/SignUpViewController.swift @@ -22,16 +22,6 @@ final class SignUpViewController: UIViewController { $0.addTarget(self, action: #selector(didTapSignUpConfirmButton), for: .touchUpInside) } - - - //MARK: Objc function - @objc private func didTapSignUpConfirmButton(){ - let vc = LoginConfirmViewController() - vc.modalPresentationStyle = .formSheet - vc.configEmail(emailTextField.text ?? "") - vc.delegate = self - present(vc, animated: true) - } //MARK: viewDidLoad override func viewDidLoad() { @@ -43,13 +33,8 @@ final class SignUpViewController: UIViewController { } -extension SignUpViewController : LoginConfirmViewControllerDelegate{ - func dismissNavigationController(){ - self.navigationController?.dismiss(animated: true) - } -} - extension SignUpViewController{ + //MARK: - Layout Helper private func setSignUpViewControllerLayout(){ [startLabel, emailTextField, passwordTextField, passwordCheckTextField, signUpConfirmButton].forEach { view.addSubview($0) @@ -79,5 +64,19 @@ extension SignUpViewController{ make.height.equalTo(44) } } + //MARK: Objc function + @objc private func didTapSignUpConfirmButton(){ + let vc = LoginConfirmViewController() + vc.modalPresentationStyle = .formSheet + vc.configEmail(emailTextField.text ?? "") + vc.delegate = self + present(vc, animated: true) + } + +} +extension SignUpViewController : LoginConfirmViewControllerDelegate{ + func dismissNavigationController(){ + self.navigationController?.dismiss(animated: true) + } } diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewModel/.gitkeep b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewModel/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/Chat/View/ Cell/ChattingTableViewCell.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/Chat/View/ Cell/ChattingTableViewCell.swift index 877a993..c6bf981 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/Chat/View/ Cell/ChattingTableViewCell.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/Chat/View/ Cell/ChattingTableViewCell.swift @@ -7,7 +7,10 @@ import UIKit -final class ChattingTableViewCell: UITableViewCell { +final class ChattingTableViewCell: UITableViewCell, UITableViewRegisterable { + + static var isFromNib: Bool = false + private let profileImageView = UIImageView().then { $0.contentMode = .scaleAspectFit } diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/Chat/View/ChattingView.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/Chat/View/ChattingView.swift index 0f2f4ed..e59000e 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/Chat/View/ChattingView.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/Chat/View/ChattingView.swift @@ -39,7 +39,8 @@ class ChattingView: UIView { private lazy var chattingTableView = UITableView(frame: .zero, style: .grouped).then { $0.register(ChattingTableViewHeaderView.self, forHeaderFooterViewReuseIdentifier: ChattingTableViewHeaderView.identifier) - $0.register(ChattingTableViewCell.self) +// $0.register(ChattingTableViewCell.self) + ChattingTableViewCell.register(target: $0) $0.translatesAutoresizingMaskIntoConstraints = false } override init(frame: CGRect) { @@ -71,7 +72,7 @@ extension ChattingView : UITableViewDelegate, UITableViewDataSource{ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - guard let cell = chattingTableView.dequeueReusableCell(withIdentifier: ChattingTableViewCell.identifier, for: indexPath) as? ChattingTableViewCell else { return UITableViewCell() } + guard let cell = chattingTableView.dequeueReusableCell(withIdentifier: ChattingTableViewCell.className, for: indexPath) as? ChattingTableViewCell else { return UITableViewCell() } cell.chattingRoomconfigure(chatting: chattings[indexPath.row]) return cell } diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/Friend/View/Cell/FriendTableViewCell.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/Friend/View/Cell/FriendTableViewCell.swift index cde9e34..c41c9e6 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/Friend/View/Cell/FriendTableViewCell.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/Friend/View/Cell/FriendTableViewCell.swift @@ -13,7 +13,9 @@ enum UserType{ case friend } -final class FriendTableViewCell: UITableViewCell { +final class FriendTableViewCell: UITableViewCell, UITableViewRegisterable { + static var isFromNib: Bool = false + private var userType: UserType? private let profileImageView = UIImageView().then { diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/Friend/ViewController/FriendViewController.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/Friend/ViewController/FriendViewController.swift index 5467ea1..932f29a 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/Friend/ViewController/FriendViewController.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/Friend/ViewController/FriendViewController.swift @@ -10,7 +10,7 @@ import SnapKit import Then final class FriendViewController: UIViewController { - var ownerUser = User(name: "유서린", stateMessage: "상태메세지는 여기에") + var ownerUser = User(name: "유서린", profileImg: Image.defaultProfileImage!, stateMessage: "상태메세지는 여기에") var users: [User] = [ User(name: "안솝트", profileImg: Image.profileImg[0]!, stateMessage: "언제 볼건데?"), User(name: "최솝트", profileImg: Image.profileImg[1]!, stateMessage: "피곤해요"), @@ -38,14 +38,14 @@ final class FriendViewController: UIViewController { $0.tintColor = .black } private lazy var friendsTableView = UITableView().then{ - $0.register(FriendTableViewCell.self) + FriendTableViewCell.register(target: $0) $0.translatesAutoresizingMaskIntoConstraints = false } override func viewDidLoad() { super.viewDidLoad() addConfigure() -// loginInit() + loginInit() setLayout() } } @@ -91,7 +91,7 @@ extension FriendViewController : UITableViewDelegate, UITableViewDataSource{ } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - guard let cell = friendsTableView.dequeueReusableCell(withIdentifier: FriendTableViewCell.identifier, for: indexPath) as? FriendTableViewCell else { return UITableViewCell() } + guard let cell = friendsTableView.dequeueReusableCell(withIdentifier: FriendTableViewCell.className, for: indexPath) as? FriendTableViewCell else { return UITableViewCell() } if(indexPath.row == 0){ cell.configureUser(ownerUser, userType: .owner) }else{ diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/Friend/ViewModel/FriendViewModel.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/Friend/ViewModel/FriendViewModel.swift index 44e81c7..7d48227 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/Friend/ViewModel/FriendViewModel.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/Friend/ViewModel/FriendViewModel.swift @@ -1,48 +1,48 @@ +//// +//// FriendViewModel.swift +//// Kakao_MVVM +//// +//// Created by Mac Book Pro on 2022/10/27. +//// // -// FriendViewModel.swift -// Kakao_MVVM +//import Foundation +//import RxSwift +//import RxCocoa // -// Created by Mac Book Pro on 2022/10/27. -// - -import Foundation -import RxSwift -import RxCocoa - -class FriendViewModel{ - var users: [User] = [ - User(name: "안솝트", profileImg: Image.profileImg[0]!, stateMessage: "언제 볼건데?"), - User(name: "최솝트", profileImg: Image.profileImg[1]!, stateMessage: "피곤해요"), - User(name: "정솝트", profileImg: Image.profileImg[2]!, stateMessage: "살려줘요"), - User(name: "강솝트", profileImg: Image.profileImg[3]!, stateMessage: "살려줘요"), - User(name: "오솝트", profileImg: Image.profileImg[4]!, stateMessage: "살려줘요"), - User(name: "황솝트", profileImg: Image.profileImg[5]!, stateMessage: "살려줘요"), - User(name: "최솝트", profileImg: Image.profileImg[6]!, stateMessage: "살려줘요"), - User(name: "고솝트", profileImg: Image.profileImg[7]!, stateMessage: "살려줘요"), - User(name: "허솝트", profileImg: Image.profileImg[8]!, stateMessage: "살려줘요"), - User(name: "허솝트", profileImg: Image.profileImg[8]!, stateMessage: "살려줘요"), - User(name: "허솝트", profileImg: Image.profileImg[8]!, stateMessage: "살려줘요"), - User(name: "허솝트", profileImg: Image.profileImg[8]!, stateMessage: "살려줘요"), - User(name: "허솝트", profileImg: Image.profileImg[8]!, stateMessage: "살려줘요"), - User(name: "허솝트", profileImg: Image.profileImg[8]!, stateMessage: "살려줘요"), - User(name: "허솝트", profileImg: Image.profileImg[8]!, stateMessage: "살려줘요") - ] - - private lazy var subject = BehaviorSubject<[User]>(value: self.users) - - let disposeBag = DisposeBag() - -// var test : Observable - - - init(){ - - } - - @discardableResult - func testFunc()->Observable<[User]>{ - users = [User(name: "안솝트", profileImg: Image.profileImg[0]!, stateMessage: "언제 볼건데?")] - subject.onNext(users) -// subject.onNext(",,,,,🧎‍♂️🧎‍♂️🧎‍♂️") - } -} +//class FriendViewModel{ +// var users: [User] = [ +// User(name: "안솝트", profileImg: Image.profileImg[0]!, stateMessage: "언제 볼건데?"), +// User(name: "최솝트", profileImg: Image.profileImg[1]!, stateMessage: "피곤해요"), +// User(name: "정솝트", profileImg: Image.profileImg[2]!, stateMessage: "살려줘요"), +// User(name: "강솝트", profileImg: Image.profileImg[3]!, stateMessage: "살려줘요"), +// User(name: "오솝트", profileImg: Image.profileImg[4]!, stateMessage: "살려줘요"), +// User(name: "황솝트", profileImg: Image.profileImg[5]!, stateMessage: "살려줘요"), +// User(name: "최솝트", profileImg: Image.profileImg[6]!, stateMessage: "살려줘요"), +// User(name: "고솝트", profileImg: Image.profileImg[7]!, stateMessage: "살려줘요"), +// User(name: "허솝트", profileImg: Image.profileImg[8]!, stateMessage: "살려줘요"), +// User(name: "허솝트", profileImg: Image.profileImg[8]!, stateMessage: "살려줘요"), +// User(name: "허솝트", profileImg: Image.profileImg[8]!, stateMessage: "살려줘요"), +// User(name: "허솝트", profileImg: Image.profileImg[8]!, stateMessage: "살려줘요"), +// User(name: "허솝트", profileImg: Image.profileImg[8]!, stateMessage: "살려줘요"), +// User(name: "허솝트", profileImg: Image.profileImg[8]!, stateMessage: "살려줘요"), +// User(name: "허솝트", profileImg: Image.profileImg[8]!, stateMessage: "살려줘요") +// ] +// +// private lazy var subject = BehaviorSubject<[User]>(value: self.users) +// +// let disposeBag = DisposeBag() +// +//// var test : Observable +// +// +// init(){ +// +// } +// +// @discardableResult +// func testFunc()->Observable<[User]>{ +// users = [User(name: "안솝트", profileImg: Image.profileImg[0]!, stateMessage: "언제 볼건데?")] +// subject.onNext(users) +//// subject.onNext(",,,,,🧎‍♂️🧎‍♂️🧎‍♂️") +// } +//} diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/MainTabBarController.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/MainTabBarController.swift index d58547d..2fdaaa6 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/MainTabBarController.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Tabbar/MainTabBarController.swift @@ -41,9 +41,6 @@ final class MainTabBarController: UITabBarController { fifthViewController.tabBarItem.selectedImage = UIImage(systemName: "ellipsis") viewControllers = [firstViewController, secondViewController, thirdViewController, fourthViewController, fifthViewController] - - - } } diff --git a/Kakao_MVVM/Kakao_MVVM/Utils/CustomView/LoginTextField.swift b/Kakao_MVVM/Kakao_MVVM/Utils/CustomView/LoginTextField.swift index 3775584..04d5468 100644 --- a/Kakao_MVVM/Kakao_MVVM/Utils/CustomView/LoginTextField.swift +++ b/Kakao_MVVM/Kakao_MVVM/Utils/CustomView/LoginTextField.swift @@ -1,8 +1,8 @@ // // LoginTextField.swift -// Kakao_MVVM +// SOPT-Assignment-KAKAO // -// Created by Mac Book Pro on 2022/10/27. +// Created by Mac Book Pro on 2022/10/23. // import Foundation @@ -47,4 +47,3 @@ final class LogintextField : UITextField{ } - diff --git a/Kakao_MVVM/Kakao_MVVM/Utils/CustomView/ProfileButton.swift b/Kakao_MVVM/Kakao_MVVM/Utils/CustomView/ProfileButton.swift index 4641d77..bb99b04 100644 --- a/Kakao_MVVM/Kakao_MVVM/Utils/CustomView/ProfileButton.swift +++ b/Kakao_MVVM/Kakao_MVVM/Utils/CustomView/ProfileButton.swift @@ -1,8 +1,8 @@ // // ProfileButton.swift -// Kakao_MVVM +// SOPT-Assignment-KAKAO // -// Created by Mac Book Pro on 2022/10/27. +// Created by Mac Book Pro on 2022/10/25. // import Foundation @@ -15,7 +15,6 @@ enum ProfileButtonType{ } final class ProfileButton : UIButton{ - init(frame: CGRect, profileButtonType: ProfileButtonType) { super.init(frame: frame) self.tintColor = .white @@ -62,4 +61,3 @@ final class ProfileButton : UIButton{ } } - diff --git a/Kakao_MVVM/Kakao_MVVM/Utils/NameSpace/ImageName.swift b/Kakao_MVVM/Kakao_MVVM/Utils/NameSpace/ImageName.swift deleted file mode 100644 index 34d8c03..0000000 --- a/Kakao_MVVM/Kakao_MVVM/Utils/NameSpace/ImageName.swift +++ /dev/null @@ -1,31 +0,0 @@ -// -// ImageName.swift -// Kakao_MVVM -// -// Created by Mac Book Pro on 2022/10/27. -// - -import UIKit - -public enum Image{ - public static let defaultProfileImage = UIImage(named: "profileImage") - public static let profileMessageButtonImg = UIImage(systemName: "message.fill") - public static let profileStoryButtonImg = UIImage(named: "profileStoryImg") - public static let profileEditButtonImg = UIImage(named: "profileEditImg") - - public static let settingButtonImage = UIImage(systemName: "gearshape") - public static let plusButtonImage = UIImage(systemName: "plus") - - public static let chattingBannerImg = UIImage(named: "chattingBannerImg") - public static let profileImg = [ - UIImage(named: "profileImage1"), - UIImage(named: "profileImage2"), - UIImage(named: "profileImage3"), - UIImage(named: "profileImage4"), - UIImage(named: "profileImage5"), - UIImage(named: "profileImage6"), - UIImage(named: "profileImage7"), - UIImage(named: "profileImage8"), - UIImage(named: "profileImage9"), - ] -} diff --git a/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO.xcodeproj/project.pbxproj b/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO.xcodeproj/project.pbxproj index 9cf313d..cac90ce 100644 --- a/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO.xcodeproj/project.pbxproj +++ b/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO.xcodeproj/project.pbxproj @@ -32,7 +32,6 @@ 52CA2AF129091BC900FA727A /* ChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52CA2AF029091BC900FA727A /* ChatViewController.swift */; }; 52CACA1C28F3FD6A001ADB19 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52CACA1B28F3FD6A001ADB19 /* AppDelegate.swift */; }; 52CACA1E28F3FD6A001ADB19 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52CACA1D28F3FD6A001ADB19 /* SceneDelegate.swift */; }; - 52CACA2328F3FD6A001ADB19 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 52CACA2128F3FD6A001ADB19 /* Main.storyboard */; }; 52CACA2528F3FD6C001ADB19 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 52CACA2428F3FD6C001ADB19 /* Assets.xcassets */; }; 52CACA2828F3FD6C001ADB19 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 52CACA2628F3FD6C001ADB19 /* LaunchScreen.storyboard */; }; 52CACA3428F3FDEC001ADB19 /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52CACA3328F3FDEC001ADB19 /* LoginViewController.swift */; }; @@ -69,7 +68,6 @@ 52CACA1828F3FD6A001ADB19 /* SOPT-Assignment-KAKAO.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "SOPT-Assignment-KAKAO.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 52CACA1B28F3FD6A001ADB19 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 52CACA1D28F3FD6A001ADB19 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; - 52CACA2228F3FD6A001ADB19 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 52CACA2428F3FD6C001ADB19 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 52CACA2728F3FD6C001ADB19 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 52CACA2928F3FD6C001ADB19 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -269,9 +267,9 @@ 52CACA1A28F3FD6A001ADB19 /* SOPT-Assignment-KAKAO */ = { isa = PBXGroup; children = ( + 52CACA3028F3FD8A001ADB19 /* Resource */, 52A3B50B2905308500983366 /* Model */, 52CACA3128F3FDB1001ADB19 /* View */, - 52CACA3028F3FD8A001ADB19 /* Resource */, 52CACA2F28F3FD80001ADB19 /* ViewController */, 52A3B4FF2905213400983366 /* Util */, 52CACA2928F3FD6C001ADB19 /* Info.plist */, @@ -311,7 +309,6 @@ 52CACA3228F3FDB8001ADB19 /* Storybaords */ = { isa = PBXGroup; children = ( - 52CACA2128F3FD6A001ADB19 /* Main.storyboard */, 52CACA2628F3FD6C001ADB19 /* LaunchScreen.storyboard */, ); path = Storybaords; @@ -397,7 +394,6 @@ files = ( 52CACA2828F3FD6C001ADB19 /* LaunchScreen.storyboard in Resources */, 52CACA2528F3FD6C001ADB19 /* Assets.xcassets in Resources */, - 52CACA2328F3FD6A001ADB19 /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -443,14 +439,6 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ - 52CACA2128F3FD6A001ADB19 /* Main.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 52CACA2228F3FD6A001ADB19 /* Base */, - ); - name = Main.storyboard; - sourceTree = ""; - }; 52CACA2628F3FD6C001ADB19 /* LaunchScreen.storyboard */ = { isa = PBXVariantGroup; children = ( diff --git a/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/Model/Chatting.swift b/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/Model/Chatting.swift index 7679336..a4731d0 100644 --- a/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/Model/Chatting.swift +++ b/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/Model/Chatting.swift @@ -12,3 +12,5 @@ struct Chatting{ var lastMessage: String var lastMessageTime : String } + + diff --git a/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/Resource/SceneDelegate.swift b/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/Resource/SceneDelegate.swift index b478e68..4b64c62 100644 --- a/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/Resource/SceneDelegate.swift +++ b/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/Resource/SceneDelegate.swift @@ -23,11 +23,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { let window = UIWindow(windowScene: windowScene) window.overrideUserInterfaceStyle = UIUserInterfaceStyle.light - let rootVC = FriendViewController() - let navigationController = UINavigationController(rootViewController: rootVC) - let mainVC = MainTabBarController() - window.rootViewController = mainVC window.makeKeyAndVisible() self.window = window diff --git a/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/View/Storybaords/Base.lproj/Main.storyboard b/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/View/Storybaords/Base.lproj/Main.storyboard deleted file mode 100644 index 0ba1290..0000000 --- a/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/View/Storybaords/Base.lproj/Main.storyboard +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/ViewController/Core Tabs/Friend/Cell/FriendTableViewCell.swift b/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/ViewController/Core Tabs/Friend/Cell/FriendTableViewCell.swift index 61d1a8e..84f5d57 100644 --- a/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/ViewController/Core Tabs/Friend/Cell/FriendTableViewCell.swift +++ b/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/ViewController/Core Tabs/Friend/Cell/FriendTableViewCell.swift @@ -8,7 +8,7 @@ import UIKit import SwiftyColor -enum UserType{ +enum UserType { case owner case friend } diff --git a/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/ViewController/Core Tabs/Friend/FriendViewController.swift b/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/ViewController/Core Tabs/Friend/FriendViewController.swift index 2491261..9da32b4 100644 --- a/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/ViewController/Core Tabs/Friend/FriendViewController.swift +++ b/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/ViewController/Core Tabs/Friend/FriendViewController.swift @@ -27,7 +27,11 @@ final class FriendViewController: UIViewController { User(name: "허솝트", profileImg: Image.profileImg[8]!, stateMessage: "살려줘요"), User(name: "허솝트", profileImg: Image.profileImg[8]!, stateMessage: "살려줘요"), User(name: "허솝트", profileImg: Image.profileImg[8]!, stateMessage: "살려줘요") - ] + ] { + didSet { + friendsTableView.reloadData() + } + } private let friendLabel = UILabel().then{ $0.font = .systemFont(ofSize: 22, weight: .bold) @@ -103,11 +107,7 @@ extension FriendViewController : UITableViewDelegate, UITableViewDataSource{ } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { - if(indexPath.row == 0){ - return 73 - }else{ - return 50 - } + indexPath.row == 0 ? 73 : 50 } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { @@ -118,7 +118,7 @@ extension FriendViewController : UITableViewDelegate, UITableViewDataSource{ }else{ vc.setProfile(user: users[indexPath.row-1], userType: .friend) } - present(vc, animated: true) + self.present(vc, animated: true) } func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { diff --git a/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/ViewController/Other/Auth/LoginViewController.swift b/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/ViewController/Other/Auth/LoginViewController.swift index cb669c0..32c0f71 100644 --- a/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/ViewController/Other/Auth/LoginViewController.swift +++ b/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/ViewController/Other/Auth/LoginViewController.swift @@ -10,7 +10,7 @@ import Then final class LoginViewController: UIViewController { //MARK: UIView - private let startLabel = UILabel().then{ + private let startLabel = UILabel().then { $0.text = "카카오톡을 시작합니다" $0.font = .systemFont(ofSize: 20) } @@ -49,18 +49,15 @@ final class LoginViewController: UIViewController { present(vc, animated: true) } - @objc private func didTapSignUpButton(){ + @objc private func didTapSignUpButton() { self.navigationController?.pushViewController(SignUpViewController(), animated: true) } - - //MARK: viewDidLoad override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .white setLoginViewControllerLayout() - signUpButton.addTarget(self, action: #selector(didTapSignUpButton), for: .touchUpInside) } } diff --git a/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/ViewController/Other/Auth/SignUpViewController.swift b/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/ViewController/Other/Auth/SignUpViewController.swift index 46e6a0f..43b0400 100644 --- a/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/ViewController/Other/Auth/SignUpViewController.swift +++ b/SOPT-Assignment-KAKAO/SOPT-Assignment-KAKAO/ViewController/Other/Auth/SignUpViewController.swift @@ -23,7 +23,7 @@ final class SignUpViewController: UIViewController { $0.isSecureTextEntry = true } - private let signUpConfirmButton = UIButton().then{ + private let signUpConfirmButton = UIButton().then { $0.configureButton(title: "새로운 카카오계정 만들기") $0.addTarget(self, action: #selector(didTapSignUpConfirmButton), for: .touchUpInside) } @@ -31,7 +31,7 @@ final class SignUpViewController: UIViewController { //MARK: Objc function - @objc private func didTapSignUpConfirmButton(){ + @objc private func didTapSignUpConfirmButton() { let vc = LoginCheckViewController() vc.modalPresentationStyle = .formSheet vc.configEmail(emailTextField.text ?? "") @@ -42,48 +42,54 @@ final class SignUpViewController: UIViewController { //MARK: viewDidLoad override func viewDidLoad() { super.viewDidLoad() - view.backgroundColor = .white + view.backgroundColor = .white setSignUpViewControllerLayout() } } -extension SignUpViewController : LoginCheckViewControllerDelegate{ +extension SignUpViewController: LoginCheckViewControllerDelegate{ func dismissNavigationController(){ self.navigationController?.dismiss(animated: true) } } -extension SignUpViewController{ - private func setSignUpViewControllerLayout(){ +extension SignUpViewController { + + private func setSignUpViewControllerLayout() { + [startLabel, emailTextField, passwordTextField, passwordCheckTextField, signUpConfirmButton].forEach { view.addSubview($0) } + startLabel.snp.makeConstraints { make in make.top.equalTo(view.safeAreaLayoutGuide).offset(40) make.centerX.equalToSuperview() } + emailTextField.snp.makeConstraints { make in make.top.equalTo(startLabel.snp.bottom).offset(116) make.leading.trailing.equalToSuperview().inset(21) make.height.equalTo(49) } + passwordTextField.snp.makeConstraints { make in make.top.equalTo(emailTextField.snp.bottom).offset(10) make.leading.trailing.equalToSuperview().inset(21) make.height.equalTo(49) } + passwordCheckTextField.snp.makeConstraints { make in make.top.equalTo(passwordTextField.snp.bottom).offset(10) make.leading.trailing.equalToSuperview().inset(21) make.height.equalTo(49) } + signUpConfirmButton.snp.makeConstraints { make in make.top.equalTo(passwordCheckTextField.snp.bottom).offset(26) make.leading.trailing.equalToSuperview().inset(21) make.height.equalTo(44) } } - } From 8a3dde87e1fff2f8184c07d612dd7a15b23262ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B2=E1=84=89=E1=85=A5=E1=84=85=E1=85=B5?= =?UTF-8?q?=E1=86=AB?= Date: Fri, 25 Nov 2022 22:02:26 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[Refactor]=20=20#6=20-=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EC=84=B1=EA=B3=B5=20=EB=B7=B0=20=EB=A6=AC=ED=8E=99?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Kakao_MVVM.xcodeproj/project.pbxproj | 8 +- .../xcshareddata/swiftpm/Package.resolved | 4 +- .../LoginConfirmViewController.swift | 25 +++- .../ViewModel/LogInConfirmViewModel.swift | 39 ++++++ .../ViewController/SignInViewController.swift | 122 ++++++++++------- .../ViewController/TestViewController.swift | 32 ----- .../SignIn/ViewModel/SignInViewModel.swift | 123 ++++++------------ .../ViewController/SignUpViewController.swift | 2 +- 8 files changed, 178 insertions(+), 177 deletions(-) create mode 100644 Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewModel/LogInConfirmViewModel.swift delete mode 100644 Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/TestViewController.swift diff --git a/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.pbxproj b/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.pbxproj index d4858e5..e8a04ff 100644 --- a/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.pbxproj +++ b/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 5204F298293006AC002051F2 /* LogInConfirmViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5204F297293006AC002051F2 /* LogInConfirmViewModel.swift */; }; 521F1A25291A41710039A477 /* .gitkeep in Resources */ = {isa = PBXBuildFile; fileRef = 521F1A24291A41710039A477 /* .gitkeep */; }; 521F1A2B291E20720039A477 /* Moya in Frameworks */ = {isa = PBXBuildFile; productRef = 521F1A2A291E20720039A477 /* Moya */; }; 525379C2290276DB00682E0B /* RxCocoa in Frameworks */ = {isa = PBXBuildFile; productRef = 525379C1290276DB00682E0B /* RxCocoa */; }; @@ -48,10 +49,10 @@ 52B59C8F290A26F500844BE7 /* MoreViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B59C8E290A26F500844BE7 /* MoreViewController.swift */; }; 52F42F39290A86E4005680BC /* FriendViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52F42F38290A86E4005680BC /* FriendViewModel.swift */; }; 52F42F3B290AA645005680BC /* SignInViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52F42F3A290AA645005680BC /* SignInViewModel.swift */; }; - 52F42F3D290AB137005680BC /* TestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52F42F3C290AB137005680BC /* TestViewController.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 5204F297293006AC002051F2 /* LogInConfirmViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogInConfirmViewModel.swift; sourceTree = ""; }; 521F1A24291A41710039A477 /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; 525379EB29027E0900682E0B /* SignInViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInViewController.swift; sourceTree = ""; }; 525379ED29027E4500682E0B /* SignUpViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpViewController.swift; sourceTree = ""; }; @@ -89,7 +90,6 @@ 52B59C8E290A26F500844BE7 /* MoreViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoreViewController.swift; sourceTree = ""; }; 52F42F38290A86E4005680BC /* FriendViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendViewModel.swift; sourceTree = ""; }; 52F42F3A290AA645005680BC /* SignInViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInViewModel.swift; sourceTree = ""; }; - 52F42F3C290AB137005680BC /* TestViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -242,7 +242,6 @@ isa = PBXGroup; children = ( 525379EB29027E0900682E0B /* SignInViewController.swift */, - 52F42F3C290AB137005680BC /* TestViewController.swift */, ); path = ViewController; sourceTree = ""; @@ -273,6 +272,7 @@ 525379E529027CBD00682E0B /* ViewModel */ = { isa = PBXGroup; children = ( + 5204F297293006AC002051F2 /* LogInConfirmViewModel.swift */, ); path = ViewModel; sourceTree = ""; @@ -681,7 +681,7 @@ 525379F62902809F00682E0B /* FriendViewController.swift in Sources */, 52B59C8D290A26D500844BE7 /* ShoppingViewController.swift in Sources */, 52B59C66290A207300844BE7 /* UITableView +.swift in Sources */, - 52F42F3D290AB137005680BC /* TestViewController.swift in Sources */, + 5204F298293006AC002051F2 /* LogInConfirmViewModel.swift in Sources */, 52B59C83290A265A00844BE7 /* ChattingTableViewCell.swift in Sources */, 525379F029027E7000682E0B /* LoginConfirmViewController.swift in Sources */, 52B59C58290A1F6A00844BE7 /* Chatting.swift in Sources */, diff --git a/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 1414830..843e9e5 100644 --- a/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/Alamofire/Alamofire.git", "state" : { - "revision" : "8dd85aee02e39dd280c75eef88ffdb86eed4b07b", - "version" : "5.6.2" + "revision" : "78424be314842833c04bc3bef5b72e85fff99204", + "version" : "5.6.4" } }, { diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewController/LoginConfirmViewController.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewController/LoginConfirmViewController.swift index 7c20cc8..4f8b6e0 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewController/LoginConfirmViewController.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewController/LoginConfirmViewController.swift @@ -1,11 +1,15 @@ import UIKit - +import RxSwift +import RxCocoa protocol LoginConfirmViewControllerDelegate : AnyObject{ func dismissNavigationController() } class LoginConfirmViewController: UIViewController { + + private let disposeBag = DisposeBag() + public var viewModel: LogInConfirmViewModel? //MARK: UIView private let welcomeLabel : UILabel = { let label = UILabel() @@ -23,7 +27,6 @@ class LoginConfirmViewController: UIViewController { //MARK: Objc function @objc private func didTapConfirmButton(){ self.dismiss(animated: true) - print(delegate.self) delegate?.dismissNavigationController() } @@ -36,15 +39,23 @@ class LoginConfirmViewController: UIViewController { setLoginCheckViewControllerLayout() confirmBtn.addTarget(self, action: #selector(didTapConfirmButton), for: .touchUpInside) + + setDataBindRx() } - public func configEmail(_ email : String){ - welcomeLabel.text = "\(email)님\n 환영합니다" - } +// public func configEmail(_ email : String){ +// welcomeLabel.text = "\(email)님\n 환영합니다" +// } } - - extension LoginConfirmViewController{ + private func setDataBindRx(){ + viewModel?.loginUser + .map{ + "\($0.email)님\n 환영합니다" + } + .bind(to: welcomeLabel.rx.text) + .disposed(by: disposeBag) + } private func setLoginCheckViewControllerLayout(){ view.addSubview(welcomeLabel) view.addSubview(confirmBtn) diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewModel/LogInConfirmViewModel.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewModel/LogInConfirmViewModel.swift new file mode 100644 index 0000000..b7ecc4c --- /dev/null +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewModel/LogInConfirmViewModel.swift @@ -0,0 +1,39 @@ +// +// LogInConfirmViewModel.swift +// Kakao_MVVM +// +// Created by Mac Book Pro on 2022/11/25. +// + +import UIKit +import RxSwift + +struct LogInConfirmViewModel { + + let disposeBag = DisposeBag() + + //MARK: - Input +// public var userName: AnyObserver +// public var userName: String + + + //MARK: - Output + public let welcomeString: Observable + public var loginUser: Observable + + init(loginUser: Observable) { + + let getUserName = PublishSubject() + let welcomUser = PublishSubject() + + self.loginUser = loginUser + + getUserName + .subscribe { userName in + welcomUser.onNext("\(userName)님 환영합니다!") + } + + welcomeString = welcomUser + } +} + diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/SignInViewController.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/SignInViewController.swift index 72a22b4..c7709f6 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/SignInViewController.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/SignInViewController.swift @@ -5,60 +5,84 @@ // Created by Mac Book Pro on 2022/10/05. // -import UIKit -import Then import RxSwift import RxCocoa +import Then +import UIKit class SignInViewController: UIViewController { -// private var viewModel = SignInViewModel() + + private var signInViewModel = SignInViewModel() private let disposeBag = DisposeBag() //MARK: UIView - private let startLabel = UILabel().then{ - $0.text = "카카오톡을 시작합니다" - $0.font = .systemFont(ofSize: 20) - } - private let explainLabel = UILabel().then{ - $0.text = "사용하던 카카오계정이 있다면 \n 이메일 또는 전화번호로 로그인해 주세요." - $0.numberOfLines = 2 - $0.textColor = .lightGray - $0.textAlignment = .center - } - private let emailTextField = LogintextField(frame: .zero, "이메일 또는 전화번호") - - private let passwordTextField = LogintextField(frame: .zero, "비밀번호").then{ - $0.isSecureTextEntry = true - } - - private let loginButton = UIButton().then{ - $0.configureButton(title: "카카오계정 로그인") - $0.addTarget(self, action: #selector(didTapLoginButton), for: .touchUpInside) - } - - private let signUpButton = UIButton().then{ - $0.configureButton(title: "새로운 카카오계정 만들기") - } - - private let findAccountLabel = UILabel().then{ - $0.text = "카카오계정 또는 비밀번호 찾기" - $0.textAlignment = .center - } - - //MARK: viewDidLoad - override func viewDidLoad() { - super.viewDidLoad() - view.backgroundColor = .white - setLoginViewControllerLayout() - - signUpButton.addTarget(self, action: #selector(didTapSignUpButton), for: .touchUpInside) - } + private let startLabel = UILabel().then{ + $0.text = "카카오톡을 시작합니다" + $0.font = .systemFont(ofSize: 20) + } + + private let explainLabel = UILabel().then{ + $0.text = "사용하던 카카오계정이 있다면 \n 이메일 또는 전화번호로 로그인해 주세요." + $0.numberOfLines = 2 + $0.textColor = .lightGray + $0.textAlignment = .center + } + private let emailTextField = LogintextField(frame: .zero, "이메일 또는 전화번호") + + private let passwordTextField = LogintextField(frame: .zero, "비밀번호").then{ + $0.isSecureTextEntry = true + } + + private let loginButton = UIButton().then{ + $0.configureButton(title: "카카오계정 로그인") + $0.addTarget(self, action: #selector(didTapLoginButton), for: .touchUpInside) + } + + private let signUpButton = UIButton().then{ + $0.configureButton(title: "새로운 카카오계정 만들기") + } + + private let findAccountLabel = UILabel().then{ + $0.text = "카카오계정 또는 비밀번호 찾기" + $0.textAlignment = .center + } + + //MARK: viewDidLoad + override func viewDidLoad() { + super.viewDidLoad() + view.backgroundColor = .white + setLoginViewControllerLayout() + bindingRx() +// signUpButton.addTarget(self, action: #selector(didTapSignUpButton), for: .touchUpInside) + } } extension SignInViewController{ private func bindingRx(){ -// emailTextField.rx.text -// .orEmpty -// .bind(to: idValue) + emailTextField.rx.text.orEmpty + .bind(to: signInViewModel.email) + .disposed(by: disposeBag) + + passwordTextField.rx.text.orEmpty + .bind(to: signInViewModel.password) + .disposed(by: disposeBag) + + /* + signInViewModel.loginUser + .map { $0.email } + .bind(to: startLabel.rx.text) + */ + loginButton.rx.tap + .bind(to: signInViewModel.login) + .disposed(by: disposeBag) + signUpButton.rx.tap + .bind(to: signInViewModel.signUp) + .disposed(by: disposeBag) + + signInViewModel.showSignUpPage + .subscribe { + self.showSignUp() + } + .disposed(by: disposeBag) } @@ -103,7 +127,15 @@ extension SignInViewController{ @objc private func didTapLoginButton(){ let vc = LoginConfirmViewController() vc.modalPresentationStyle = .formSheet - vc.configEmail(emailTextField.text ?? "") + vc.viewModel = LogInConfirmViewModel(loginUser: signInViewModel.loginUser) + vc.delegate = self + present(vc, animated: true) + } + private func showSignUp(){ + print("hello") + let vc = LoginConfirmViewController() + vc.modalPresentationStyle = .formSheet + vc.viewModel = LogInConfirmViewModel(loginUser: signInViewModel.loginUser) vc.delegate = self present(vc, animated: true) } diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/TestViewController.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/TestViewController.swift deleted file mode 100644 index 1f57cbf..0000000 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/TestViewController.swift +++ /dev/null @@ -1,32 +0,0 @@ -//// -//// TestViewController.swift -//// Kakao_MVVM -//// -//// Created by Mac Book Pro on 2022/10/27. -//// -// -//import UIKit -//import RxSwift -// -//class TestViewController: UIViewController { -// let viewModel: SignInViewModel -// var disposeBag = DisposeBag() -// -// override func viewDidLoad() { -// super.viewDidLoad() -// -// setupBindings() -// } -// -// init(viewModel: SignInViewModel = SignInViewModel()) { -// self.viewModel = viewModel -// super.init(nibName: nil, bundle: nil) -// } -// required init?(coder aDecoder: NSCoder) { -//// viewModel = SignInViewModel() -// super.init(coder: aDecoder) -// } -// -// func setupBindings() { -// } -//} diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewModel/SignInViewModel.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewModel/SignInViewModel.swift index cdee3e1..c14bb3f 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewModel/SignInViewModel.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewModel/SignInViewModel.swift @@ -9,97 +9,48 @@ import Foundation import RxCocoa import RxSwift +struct LoginUser{ + var email: String + var password: String +} + struct SignInViewModel{ let disposeBag = DisposeBag() //MARK: - INPUT - let userLogin: AnyObserver - + public var email: AnyObserver + public var password: AnyObserver + public var login: AnyObserver + public var signUp: AnyObserver + //MARK: - OUTPUT - let loginedUser: Observable + public var loginUser: Observable + public var showSignUpPage: Observable - init(loginModel: LoginModel = LoginModel()) { - let login = PublishSubject() - userLogin = login.asObserver() - - } -} - - -struct LoginModel{ - func loginUser (email: String)-> Observable { - return Observable.create { observer in - observer.onNext(User(name: email)) - return Disposables.create() - } + init() { + let fetchEmail = PublishSubject() + let fetchPassword = PublishSubject() + let fetchLoginUser = BehaviorSubject(value: LoginUser(email: "", password: "")) + let loginTrying = PublishSubject() + let signUpTrying = PublishSubject() + + email = fetchEmail.asObserver() + password = fetchPassword.asObserver() + login = loginTrying.asObserver() + signUp = signUpTrying.asObserver() + + Observable + .combineLatest(fetchEmail, fetchPassword) + .subscribe(onNext: { + fetchLoginUser.onNext(LoginUser(email: $0, password: $1)) + }) + .disposed(by: disposeBag) + + loginUser = loginTrying.withLatestFrom(fetchLoginUser) + .map{ $0 } + + + showSignUpPage = signUpTrying +// loginUser = fetchLoginUser } } - -/* -struct SignInViewModel{ - var name : Observable - var loginUser: PublishSubject = PublishSubject() - var loginBtnTouched: PublishRelay = PublishRelay() - - var idValue: PublishRelay = PublishRelay() - var pwValue: PublishRelay = PublishRelay() - - // loginInfo 는 Observable !!!!! -> 위 값들을 합친!!!!! - var loginInfo:Observable { - // subject 들의 값을 합칠 수 있음! - return Observable.combineLatest(idValue, pwValue) { id, pw in - return id ?? "" - } - } - - - let disposeBag = DisposeBag() - - - -// 우선 여기까지 - init(model:Login = Login()) { - loginBtnTouched.withLatestFrom(loginInfo).flatMapLatest{ - return model.login(email: $0).materialize() - }.subscribe(onNext: { [unowned self] (event) in - switch event { - case .next(let user): - self.loginUser.onNext(user) - case .error(let error): - self.loginUser.onNext(nil) - case .completed: - print("COMPLTED") - } - }).disposed(by: disposeBag) - } - -} - -struct Login{ - func login(email: String) -> Observable { - return Observable.create({ (observer) -> Disposable in - - print("\(observer)") // 요기다가 비지니스 로직 (네트워크를 타고 온 것들) - - observer.onNext(email) - - return Disposables.create() - - }) - } -} -// 로직 전용 Model 에서 하는 코드 -/* -func login(name: String) -> Observable { - return Observable.create({ (observer) -> Disposable in - - print("\(observer)") // 요기다가 비지니스 로직 (네트워크를 타고 온 것들) - - observer.onNext(name) - - return Disposables.create() - - }) -} - */ -*/ diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewController/SignUpViewController.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewController/SignUpViewController.swift index 00914d1..2b782a2 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewController/SignUpViewController.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewController/SignUpViewController.swift @@ -68,7 +68,7 @@ extension SignUpViewController{ @objc private func didTapSignUpConfirmButton(){ let vc = LoginConfirmViewController() vc.modalPresentationStyle = .formSheet - vc.configEmail(emailTextField.text ?? "") +// vc.configEmail(emailTextField.text ?? "") vc.delegate = self present(vc, animated: true) } From 45662070fc810c6c63b0a25e68d768c79287b86c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B2=E1=84=89=E1=85=A5=E1=84=85=E1=85=B5?= =?UTF-8?q?=E1=86=AB?= Date: Sat, 26 Nov 2022 22:24:14 +0900 Subject: [PATCH 3/5] [Refactor] #6 - LoginConfirm MVVM Refectoring --- .../Kakao_MVVM.xcodeproj/project.pbxproj | 2 +- .../LoginConfirmViewController.swift | 70 ++++++------- .../ViewModel/LogInConfirmViewModel.swift | 16 ++- .../ViewController/SignInViewController.swift | 97 ++++++++----------- .../SignIn/ViewModel/SignInViewModel.swift | 4 +- 5 files changed, 79 insertions(+), 110 deletions(-) diff --git a/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.pbxproj b/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.pbxproj index e8a04ff..beb146d 100644 --- a/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.pbxproj +++ b/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.pbxproj @@ -166,8 +166,8 @@ 525379D629027C3400682E0B /* Auth */ = { isa = PBXGroup; children = ( - 525379DA29027C7400682E0B /* SignUp */, 525379D929027C6E00682E0B /* SignIn */, + 525379DA29027C7400682E0B /* SignUp */, 525379D829027C6800682E0B /* LoginConfirm */, ); path = Auth; diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewController/LoginConfirmViewController.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewController/LoginConfirmViewController.swift index 4f8b6e0..c4a300e 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewController/LoginConfirmViewController.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewController/LoginConfirmViewController.swift @@ -8,55 +8,45 @@ protocol LoginConfirmViewControllerDelegate : AnyObject{ class LoginConfirmViewController: UIViewController { + public weak var delegate : LoginConfirmViewControllerDelegate? + private let disposeBag = DisposeBag() - public var viewModel: LogInConfirmViewModel? - //MARK: UIView - private let welcomeLabel : UILabel = { - let label = UILabel() - label.numberOfLines = 2 - label.textAlignment = .center - label.font = .systemFont(ofSize: 20) - return label - }() - private let confirmBtn : UIButton = { - let button = UIButton() - button.configureButton(title: "확인") - button.backgroundColor = .systemYellow - return button - }() - //MARK: Objc function - @objc private func didTapConfirmButton(){ - self.dismiss(animated: true) - delegate?.dismissNavigationController() - } + private var viewModel: LogInConfirmViewModel? - public weak var delegate : LoginConfirmViewControllerDelegate? + //MARK: UIView + private let welcomeLabel: UILabel = UILabel() + private let confirmBtn: UIButton = UIButton() //MARK: viewDidLoad override func viewDidLoad() { super.viewDidLoad() - view.backgroundColor = .white - - setLoginCheckViewControllerLayout() - confirmBtn.addTarget(self, action: #selector(didTapConfirmButton), for: .touchUpInside) - - setDataBindRx() + setUI() + setLayout() } - -// public func configEmail(_ email : String){ -// welcomeLabel.text = "\(email)님\n 환영합니다" -// } } extension LoginConfirmViewController{ - private func setDataBindRx(){ - viewModel?.loginUser - .map{ - "\($0.email)님\n 환영합니다" - } + + public func setDataBindRx(_ viewModel: LogInConfirmViewModel) { + self.viewModel = viewModel + self.viewModel?.welcomeString .bind(to: welcomeLabel.rx.text) .disposed(by: disposeBag) } - private func setLoginCheckViewControllerLayout(){ + + private func setUI(){ + view.backgroundColor = .white + welcomeLabel.do { + $0.numberOfLines = 2 + $0.textAlignment = .center + $0.font = .systemFont(ofSize: 20) + } + confirmBtn.do { + $0.configureButton(title: "확인") + $0.backgroundColor = .systemYellow + } + } + private func setLayout(){ + confirmBtn.addTarget(self, action: #selector(didTapConfirmButton), for: .touchUpInside) view.addSubview(welcomeLabel) view.addSubview(confirmBtn) welcomeLabel.snp.makeConstraints { make in @@ -69,5 +59,9 @@ extension LoginConfirmViewController{ make.height.equalTo(44) } } - + //MARK: Objc function + @objc private func didTapConfirmButton(){ + self.dismiss(animated: true) + delegate?.dismissNavigationController() + } } diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewModel/LogInConfirmViewModel.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewModel/LogInConfirmViewModel.swift index b7ecc4c..39ea754 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewModel/LogInConfirmViewModel.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewModel/LogInConfirmViewModel.swift @@ -13,25 +13,21 @@ struct LogInConfirmViewModel { let disposeBag = DisposeBag() //MARK: - Input -// public var userName: AnyObserver -// public var userName: String - //MARK: - Output public let welcomeString: Observable public var loginUser: Observable init(loginUser: Observable) { - - let getUserName = PublishSubject() let welcomUser = PublishSubject() - self.loginUser = loginUser - getUserName - .subscribe { userName in - welcomUser.onNext("\(userName)님 환영합니다!") - } + loginUser + .map{"\($0.email)님\n 환영합니다"} + .subscribe(onNext: { + welcomUser.onNext($0) + }) + .disposed(by: disposeBag) welcomeString = welcomUser } diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/SignInViewController.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/SignInViewController.swift index c7709f6..6f88315 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/SignInViewController.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/SignInViewController.swift @@ -16,44 +16,20 @@ class SignInViewController: UIViewController { private let disposeBag = DisposeBag() //MARK: UIView - private let startLabel = UILabel().then{ - $0.text = "카카오톡을 시작합니다" - $0.font = .systemFont(ofSize: 20) - } - - private let explainLabel = UILabel().then{ - $0.text = "사용하던 카카오계정이 있다면 \n 이메일 또는 전화번호로 로그인해 주세요." - $0.numberOfLines = 2 - $0.textColor = .lightGray - $0.textAlignment = .center - } + private let startLabel = UILabel() + private let explainLabel = UILabel() private let emailTextField = LogintextField(frame: .zero, "이메일 또는 전화번호") - - private let passwordTextField = LogintextField(frame: .zero, "비밀번호").then{ - $0.isSecureTextEntry = true - } - - private let loginButton = UIButton().then{ - $0.configureButton(title: "카카오계정 로그인") - $0.addTarget(self, action: #selector(didTapLoginButton), for: .touchUpInside) - } - - private let signUpButton = UIButton().then{ - $0.configureButton(title: "새로운 카카오계정 만들기") - } - - private let findAccountLabel = UILabel().then{ - $0.text = "카카오계정 또는 비밀번호 찾기" - $0.textAlignment = .center - } + private let passwordTextField = LogintextField(frame: .zero, "비밀번호") + private let loginButton = UIButton() + private let signUpButton = UIButton() + private let findAccountLabel = UILabel() //MARK: viewDidLoad override func viewDidLoad() { super.viewDidLoad() - view.backgroundColor = .white - setLoginViewControllerLayout() + setUI() + setLayout() bindingRx() -// signUpButton.addTarget(self, action: #selector(didTapSignUpButton), for: .touchUpInside) } } extension SignInViewController{ @@ -66,27 +42,40 @@ extension SignInViewController{ .bind(to: signInViewModel.password) .disposed(by: disposeBag) - /* - signInViewModel.loginUser - .map { $0.email } - .bind(to: startLabel.rx.text) - */ loginButton.rx.tap .bind(to: signInViewModel.login) .disposed(by: disposeBag) - signUpButton.rx.tap - .bind(to: signInViewModel.signUp) - .disposed(by: disposeBag) - - signInViewModel.showSignUpPage - .subscribe { - self.showSignUp() - } - .disposed(by: disposeBag) } - - private func setLoginViewControllerLayout(){ + private func setUI(){ + startLabel.do { + $0.text = "카카오톡을 시작합니다" + $0.font = .systemFont(ofSize: 20) + } + explainLabel.do { + $0.text = "사용하던 카카오계정이 있다면 \n 이메일 또는 전화번호로 로그인해 주세요." + $0.numberOfLines = 2 + $0.textColor = .lightGray + $0.textAlignment = .center + } + passwordTextField.do { + $0.isSecureTextEntry = true + } + loginButton.do { + $0.configureButton(title: "카카오계정 로그인") + $0.addTarget(self, action: #selector(didTapLoginButton), for: .touchUpInside) + } + + signUpButton.do { + $0.configureButton(title: "새로운 카카오계정 만들기") + } + findAccountLabel.do { + $0.text = "카카오계정 또는 비밀번호 찾기" + $0.textAlignment = .center + } + } + private func setLayout(){ + view.backgroundColor = .white [startLabel, explainLabel, emailTextField, passwordTextField, loginButton, signUpButton, findAccountLabel].forEach { view.addSubview($0 as! UIView) } @@ -123,19 +112,11 @@ extension SignInViewController{ make.centerX.equalToSuperview() } } - //MARK: Objc function + @objc private func didTapLoginButton(){ let vc = LoginConfirmViewController() vc.modalPresentationStyle = .formSheet - vc.viewModel = LogInConfirmViewModel(loginUser: signInViewModel.loginUser) - vc.delegate = self - present(vc, animated: true) - } - private func showSignUp(){ - print("hello") - let vc = LoginConfirmViewController() - vc.modalPresentationStyle = .formSheet - vc.viewModel = LogInConfirmViewModel(loginUser: signInViewModel.loginUser) + vc.setDataBindRx(LogInConfirmViewModel(loginUser: signInViewModel.loginUser)) vc.delegate = self present(vc, animated: true) } diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewModel/SignInViewModel.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewModel/SignInViewModel.swift index c14bb3f..9f456a2 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewModel/SignInViewModel.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewModel/SignInViewModel.swift @@ -39,7 +39,7 @@ struct SignInViewModel{ login = loginTrying.asObserver() signUp = signUpTrying.asObserver() - Observable + let _ = Observable .combineLatest(fetchEmail, fetchPassword) .subscribe(onNext: { fetchLoginUser.onNext(LoginUser(email: $0, password: $1)) @@ -47,10 +47,8 @@ struct SignInViewModel{ .disposed(by: disposeBag) loginUser = loginTrying.withLatestFrom(fetchLoginUser) - .map{ $0 } showSignUpPage = signUpTrying -// loginUser = fetchLoginUser } } From 0db535ffcb69cd3d8260d9178756c1ff1e8d2ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B2=E1=84=89=E1=85=A5=E1=84=85=E1=85=B5?= =?UTF-8?q?=E1=86=AB?= Date: Sat, 26 Nov 2022 22:34:25 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[Refector]=20#6=20setUI=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EB=A6=AC=ED=8E=99=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Kakao_MVVM.xcodeproj/project.pbxproj | 8 +-- .../LoginConfirmViewController.swift | 3 +- .../ViewController/SignInViewController.swift | 4 +- .../SignIn/ViewModel/SignInViewModel.swift | 7 +-- .../ViewController/SignUpViewController.swift | 49 ++++++++++--------- .../Auth/SignUp/ViewModel/.gitkeep | 0 .../SignUp/ViewModel/SignUpViewModel.swift | 10 ++++ 7 files changed, 46 insertions(+), 35 deletions(-) delete mode 100644 Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewModel/.gitkeep create mode 100644 Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewModel/SignUpViewModel.swift diff --git a/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.pbxproj b/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.pbxproj index beb146d..24be70e 100644 --- a/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.pbxproj +++ b/Kakao_MVVM/Kakao_MVVM.xcodeproj/project.pbxproj @@ -8,7 +8,6 @@ /* Begin PBXBuildFile section */ 5204F298293006AC002051F2 /* LogInConfirmViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5204F297293006AC002051F2 /* LogInConfirmViewModel.swift */; }; - 521F1A25291A41710039A477 /* .gitkeep in Resources */ = {isa = PBXBuildFile; fileRef = 521F1A24291A41710039A477 /* .gitkeep */; }; 521F1A2B291E20720039A477 /* Moya in Frameworks */ = {isa = PBXBuildFile; productRef = 521F1A2A291E20720039A477 /* Moya */; }; 525379C2290276DB00682E0B /* RxCocoa in Frameworks */ = {isa = PBXBuildFile; productRef = 525379C1290276DB00682E0B /* RxCocoa */; }; 525379C4290276DB00682E0B /* RxSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 525379C3290276DB00682E0B /* RxSwift */; }; @@ -25,6 +24,7 @@ 528B30522902756B00DD376E /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 528B30512902756B00DD376E /* SceneDelegate.swift */; }; 528B30592902756D00DD376E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 528B30582902756D00DD376E /* Assets.xcassets */; }; 528B305C2902756D00DD376E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 528B305A2902756D00DD376E /* LaunchScreen.storyboard */; }; + 528E289629324B1400886841 /* SignUpViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 528E289529324B1400886841 /* SignUpViewModel.swift */; }; 529FE3A3292539D000A8D7AE /* NSObject +.swift in Sources */ = {isa = PBXBuildFile; fileRef = 529FE3A2292539D000A8D7AE /* NSObject +.swift */; }; 529FE3A5292539EA00A8D7AE /* UIButton +.swift in Sources */ = {isa = PBXBuildFile; fileRef = 529FE3A4292539EA00A8D7AE /* UIButton +.swift */; }; 529FE3A729253A0500A8D7AE /* Int +.swift in Sources */ = {isa = PBXBuildFile; fileRef = 529FE3A629253A0500A8D7AE /* Int +.swift */; }; @@ -53,7 +53,6 @@ /* Begin PBXFileReference section */ 5204F297293006AC002051F2 /* LogInConfirmViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogInConfirmViewModel.swift; sourceTree = ""; }; - 521F1A24291A41710039A477 /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; 525379EB29027E0900682E0B /* SignInViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInViewController.swift; sourceTree = ""; }; 525379ED29027E4500682E0B /* SignUpViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpViewController.swift; sourceTree = ""; }; 525379EF29027E7000682E0B /* LoginConfirmViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginConfirmViewController.swift; sourceTree = ""; }; @@ -66,6 +65,7 @@ 528B30582902756D00DD376E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 528B305B2902756D00DD376E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 528B305D2902756D00DD376E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 528E289529324B1400886841 /* SignUpViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpViewModel.swift; sourceTree = ""; }; 529FE3A2292539D000A8D7AE /* NSObject +.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSObject +.swift"; sourceTree = ""; }; 529FE3A4292539EA00A8D7AE /* UIButton +.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIButton +.swift"; sourceTree = ""; }; 529FE3A629253A0500A8D7AE /* Int +.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Int +.swift"; sourceTree = ""; }; @@ -112,7 +112,7 @@ 521F1A23291A41060039A477 /* ViewModel */ = { isa = PBXGroup; children = ( - 521F1A24291A41710039A477 /* .gitkeep */, + 528E289529324B1400886841 /* SignUpViewModel.swift */, ); path = ViewModel; sourceTree = ""; @@ -660,7 +660,6 @@ files = ( 528B305C2902756D00DD376E /* LaunchScreen.storyboard in Resources */, 528B30592902756D00DD376E /* Assets.xcassets in Resources */, - 521F1A25291A41710039A477 /* .gitkeep in Resources */, 529FE3A929253D8700A8D7AE /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -703,6 +702,7 @@ 52B59C7E290A260400844BE7 /* FriendTableViewCell.swift in Sources */, 52B59C80290A264000844BE7 /* ChatViewController.swift in Sources */, 52B59C5E290A1FF400844BE7 /* LoginTextField.swift in Sources */, + 528E289629324B1400886841 /* SignUpViewModel.swift in Sources */, 52B59C89290A268400844BE7 /* ChattingTableViewHeaderView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewController/LoginConfirmViewController.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewController/LoginConfirmViewController.swift index c4a300e..9c932c8 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewController/LoginConfirmViewController.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewController/LoginConfirmViewController.swift @@ -1,3 +1,4 @@ + import UIKit import RxSwift import RxCocoa @@ -6,7 +7,7 @@ protocol LoginConfirmViewControllerDelegate : AnyObject{ func dismissNavigationController() } -class LoginConfirmViewController: UIViewController { +final class LoginConfirmViewController: UIViewController { public weak var delegate : LoginConfirmViewControllerDelegate? diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/SignInViewController.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/SignInViewController.swift index 6f88315..36f7b40 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/SignInViewController.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/SignInViewController.swift @@ -10,7 +10,7 @@ import RxCocoa import Then import UIKit -class SignInViewController: UIViewController { +final class SignInViewController: UIViewController { private var signInViewModel = SignInViewModel() private let disposeBag = DisposeBag() @@ -65,9 +65,9 @@ extension SignInViewController{ $0.configureButton(title: "카카오계정 로그인") $0.addTarget(self, action: #selector(didTapLoginButton), for: .touchUpInside) } - signUpButton.do { $0.configureButton(title: "새로운 카카오계정 만들기") + $0.addTarget(self, action: #selector(didTapSignUpButton), for: .touchUpInside) } findAccountLabel.do { $0.text = "카카오계정 또는 비밀번호 찾기" diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewModel/SignInViewModel.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewModel/SignInViewModel.swift index 9f456a2..09782df 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewModel/SignInViewModel.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewModel/SignInViewModel.swift @@ -25,14 +25,12 @@ struct SignInViewModel{ //MARK: - OUTPUT public var loginUser: Observable - public var showSignUpPage: Observable init() { let fetchEmail = PublishSubject() let fetchPassword = PublishSubject() - let fetchLoginUser = BehaviorSubject(value: LoginUser(email: "", password: "")) let loginTrying = PublishSubject() - let signUpTrying = PublishSubject() + let fetchLoginUser = BehaviorSubject(value: LoginUser(email: "", password: "")) email = fetchEmail.asObserver() password = fetchPassword.asObserver() @@ -47,8 +45,5 @@ struct SignInViewModel{ .disposed(by: disposeBag) loginUser = loginTrying.withLatestFrom(fetchLoginUser) - - - showSignUpPage = signUpTrying } } diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewController/SignUpViewController.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewController/SignUpViewController.swift index 2b782a2..667419a 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewController/SignUpViewController.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewController/SignUpViewController.swift @@ -3,39 +3,45 @@ import UIKit import Then final class SignUpViewController: UIViewController { + //MARK: UIView - private let startLabel = UILabel().then{ - $0.text = "카카오톡을 시작합니다" - $0.font = .systemFont(ofSize: 20) - } + private let startLabel = UILabel() private let emailTextField = LogintextField(frame: .zero, "이메일 또는 전화번호") - - private let passwordTextField = LogintextField(frame: .zero, "비밀번호").then{ - $0.isSecureTextEntry = true - } - private let passwordCheckTextField = LogintextField(frame: .zero, "비밀번호 확인").then{ - $0.isSecureTextEntry = true - } - - private let signUpConfirmButton = UIButton().then{ - $0.configureButton(title: "새로운 카카오계정 만들기") - $0.addTarget(self, action: #selector(didTapSignUpConfirmButton), for: .touchUpInside) - } + private let passwordTextField = LogintextField(frame: .zero, "비밀번호") + private let passwordCheckTextField = LogintextField(frame: .zero, "비밀번호 확인") + private let signUpConfirmButton = UIButton() //MARK: viewDidLoad override func viewDidLoad() { super.viewDidLoad() - view.backgroundColor = .white - - setSignUpViewControllerLayout() + setUI() + setLayout() } - } extension SignUpViewController{ + + private func setUI(){ + view.backgroundColor = .white + startLabel.do { + $0.text = "카카오톡을 시작합니다" + $0.font = .systemFont(ofSize: 20) + } + passwordTextField.do { + $0.isSecureTextEntry = true + } + passwordCheckTextField.do { + $0.isSecureTextEntry = true + } + + signUpConfirmButton.do { + $0.configureButton(title: "새로운 카카오계정 만들기") + $0.addTarget(self, action: #selector(didTapSignUpConfirmButton), for: .touchUpInside) + } + } //MARK: - Layout Helper - private func setSignUpViewControllerLayout(){ + private func setLayout(){ [startLabel, emailTextField, passwordTextField, passwordCheckTextField, signUpConfirmButton].forEach { view.addSubview($0) } @@ -68,7 +74,6 @@ extension SignUpViewController{ @objc private func didTapSignUpConfirmButton(){ let vc = LoginConfirmViewController() vc.modalPresentationStyle = .formSheet -// vc.configEmail(emailTextField.text ?? "") vc.delegate = self present(vc, animated: true) } diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewModel/.gitkeep b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewModel/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewModel/SignUpViewModel.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewModel/SignUpViewModel.swift new file mode 100644 index 0000000..46fcbf9 --- /dev/null +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewModel/SignUpViewModel.swift @@ -0,0 +1,10 @@ +// +// SignUpViewModel.swift +// Kakao_MVVM +// +// Created by Mac Book Pro on 2022/11/26. +// + +import UIKit +import RxSwift + From d1548f8f5bf10303e834938f36d87bab3c13b339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B2=E1=84=89=E1=85=A5=E1=84=85=E1=85=B5?= =?UTF-8?q?=E1=86=AB?= Date: Sun, 27 Nov 2022 02:38:09 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[Refector]=20#6=20=20SignUp=20MVVM=20-=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LoginConfirmViewController.swift | 8 ++-- .../ViewModel/LogInConfirmViewModel.swift | 4 +- .../ViewController/SignInViewController.swift | 2 + .../SignIn/ViewModel/SignInViewModel.swift | 3 +- .../ViewController/SignUpViewController.swift | 34 +++++++++++++- .../SignUp/ViewModel/SignUpViewModel.swift | 46 +++++++++++++++++++ 6 files changed, 87 insertions(+), 10 deletions(-) diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewController/LoginConfirmViewController.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewController/LoginConfirmViewController.swift index 9c932c8..a4c58ec 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewController/LoginConfirmViewController.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewController/LoginConfirmViewController.swift @@ -27,14 +27,14 @@ final class LoginConfirmViewController: UIViewController { } extension LoginConfirmViewController{ - public func setDataBindRx(_ viewModel: LogInConfirmViewModel) { + public func setDataBindRx(_ viewModel: LogInConfirmViewModel) { self.viewModel = viewModel self.viewModel?.welcomeString .bind(to: welcomeLabel.rx.text) .disposed(by: disposeBag) } - private func setUI(){ + private func setUI() { view.backgroundColor = .white welcomeLabel.do { $0.numberOfLines = 2 @@ -46,7 +46,7 @@ extension LoginConfirmViewController{ $0.backgroundColor = .systemYellow } } - private func setLayout(){ + private func setLayout() { confirmBtn.addTarget(self, action: #selector(didTapConfirmButton), for: .touchUpInside) view.addSubview(welcomeLabel) view.addSubview(confirmBtn) @@ -61,7 +61,7 @@ extension LoginConfirmViewController{ } } //MARK: Objc function - @objc private func didTapConfirmButton(){ + @objc private func didTapConfirmButton() { self.dismiss(animated: true) delegate?.dismissNavigationController() } diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewModel/LogInConfirmViewModel.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewModel/LogInConfirmViewModel.swift index 39ea754..b8962d9 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewModel/LogInConfirmViewModel.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/LoginConfirm/ViewModel/LogInConfirmViewModel.swift @@ -12,10 +12,8 @@ struct LogInConfirmViewModel { let disposeBag = DisposeBag() - //MARK: - Input - //MARK: - Output - public let welcomeString: Observable + public var welcomeString: Observable public var loginUser: Observable init(loginUser: Observable) { diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/SignInViewController.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/SignInViewController.swift index 36f7b40..24e9cf6 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/SignInViewController.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewController/SignInViewController.swift @@ -33,6 +33,7 @@ final class SignInViewController: UIViewController { } } extension SignInViewController{ + private func bindingRx(){ emailTextField.rx.text.orEmpty .bind(to: signInViewModel.email) @@ -74,6 +75,7 @@ extension SignInViewController{ $0.textAlignment = .center } } + private func setLayout(){ view.backgroundColor = .white [startLabel, explainLabel, emailTextField, passwordTextField, loginButton, signUpButton, findAccountLabel].forEach { diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewModel/SignInViewModel.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewModel/SignInViewModel.swift index 09782df..c445f29 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewModel/SignInViewModel.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignIn/ViewModel/SignInViewModel.swift @@ -21,7 +21,6 @@ struct SignInViewModel{ public var email: AnyObserver public var password: AnyObserver public var login: AnyObserver - public var signUp: AnyObserver //MARK: - OUTPUT public var loginUser: Observable @@ -35,7 +34,7 @@ struct SignInViewModel{ email = fetchEmail.asObserver() password = fetchPassword.asObserver() login = loginTrying.asObserver() - signUp = signUpTrying.asObserver() + let _ = Observable .combineLatest(fetchEmail, fetchPassword) diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewController/SignUpViewController.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewController/SignUpViewController.swift index 667419a..a644b0d 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewController/SignUpViewController.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewController/SignUpViewController.swift @@ -1,9 +1,14 @@ import UIKit import Then +import RxSwift +import RxCocoa final class SignUpViewController: UIViewController { + private var viewModel: SignUpViewModel = SignUpViewModel() + private let disposeBag = DisposeBag() + //MARK: UIView private let startLabel = UILabel() private let emailTextField = LogintextField(frame: .zero, "이메일 또는 전화번호") @@ -17,11 +22,35 @@ final class SignUpViewController: UIViewController { super.viewDidLoad() setUI() setLayout() + setDataBindingRx() } } -extension SignUpViewController{ +extension SignUpViewController { + //MARK: - Data Binding RXSwift + private func setDataBindingRx() { + emailTextField.rx.text.orEmpty + .bind(to: viewModel.userEmail) + .disposed(by: disposeBag) + + passwordTextField.rx.text.orEmpty + .bind(to: viewModel.userPassword) + .disposed(by: disposeBag) + + passwordCheckTextField.rx.text.orEmpty + .bind(to: viewModel.checkUserPassword) + .disposed(by: disposeBag) + + signUpConfirmButton.rx.tap + .bind(to: viewModel.signUp) + .disposed(by: disposeBag) + + viewModel.isSamePW + .map { $0 ? UIColor.yellow : UIColor.systemGray4 } + .bind(to: signUpConfirmButton.rx.backgroundColor) + .disposed(by: disposeBag) + } private func setUI(){ view.backgroundColor = .white startLabel.do { @@ -40,6 +69,7 @@ extension SignUpViewController{ $0.addTarget(self, action: #selector(didTapSignUpConfirmButton), for: .touchUpInside) } } + //MARK: - Layout Helper private func setLayout(){ [startLabel, emailTextField, passwordTextField, passwordCheckTextField, signUpConfirmButton].forEach { @@ -70,10 +100,12 @@ extension SignUpViewController{ make.height.equalTo(44) } } + //MARK: Objc function @objc private func didTapSignUpConfirmButton(){ let vc = LoginConfirmViewController() vc.modalPresentationStyle = .formSheet + vc.setDataBindRx( LogInConfirmViewModel(loginUser: viewModel.loginUser) ) vc.delegate = self present(vc, animated: true) } diff --git a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewModel/SignUpViewModel.swift b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewModel/SignUpViewModel.swift index 46fcbf9..a3cc27b 100644 --- a/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewModel/SignUpViewModel.swift +++ b/Kakao_MVVM/Kakao_MVVM/Presentation/Auth/SignUp/ViewModel/SignUpViewModel.swift @@ -7,4 +7,50 @@ import UIKit import RxSwift +import RxCocoa +struct SignUpViewModel { + + private let disposeBag: DisposeBag = DisposeBag() + //MARK: - Input + public let userEmail: AnyObserver + public let userPassword: AnyObserver + public let checkUserPassword: AnyObserver + public let signUp: AnyObserver + + //MARK: - Output + public let isSamePW: Observable + public var loginUser: Observable + + init(){ + let fetchEmail = PublishSubject() + let fetchPassword = PublishSubject() + let fetchChechPassword = PublishSubject() + let signUpTring = PublishSubject() + + let checkCondition = PublishSubject() + let signUpUser = PublishSubject() + + userEmail = fetchEmail.asObserver() + userPassword = fetchPassword.asObserver() + checkUserPassword = fetchChechPassword.asObserver() + signUp = signUpTring.asObserver() + + Observable + .combineLatest(fetchPassword, fetchChechPassword) + .map{ $0 == $1} + .subscribe { checkCondition.onNext($0) } + .disposed(by: disposeBag) + + isSamePW = checkCondition + + Observable + .combineLatest(fetchEmail, fetchPassword) + .subscribe { + signUpUser.onNext(LoginUser(email: $0, password: $1)) + } + .disposed(by: disposeBag) + + loginUser = signUpTring.withLatestFrom(signUpUser) + } +}