From bf2eeb0d93640d6b41d3cd1a9ae3bae207f709e0 Mon Sep 17 00:00:00 2001 From: Ryo Aoyama Date: Wed, 5 Jun 2019 07:05:44 +0900 Subject: [PATCH] Refactor --- .../project.pbxproj | 26 +++++++++---------- SwiftUI-Combine-Example/SceneDelegate.swift | 2 +- ...serSearchBar.swift => SearchUserBar.swift} | 2 +- .../{UserRow.swift => SearchUserRow.swift} | 4 ++- ...rSearchView.swift => SearchUserView.swift} | 6 ++--- 5 files changed, 21 insertions(+), 19 deletions(-) rename SwiftUI-Combine-Example/{UserSearchBar.swift => SearchUserBar.swift} (96%) rename SwiftUI-Combine-Example/{UserRow.swift => SearchUserRow.swift} (96%) rename SwiftUI-Combine-Example/{UserSearchView.swift => SearchUserView.swift} (79%) diff --git a/SwiftUI-Combine-Example.xcodeproj/project.pbxproj b/SwiftUI-Combine-Example.xcodeproj/project.pbxproj index 49f775d..9663e95 100644 --- a/SwiftUI-Combine-Example.xcodeproj/project.pbxproj +++ b/SwiftUI-Combine-Example.xcodeproj/project.pbxproj @@ -9,15 +9,15 @@ /* Begin PBXBuildFile section */ 6B194EFF22A6BA07001B3151 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194EFE22A6BA07001B3151 /* AppDelegate.swift */; }; 6B194F0122A6BA07001B3151 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194F0022A6BA07001B3151 /* SceneDelegate.swift */; }; - 6B194F0322A6BA07001B3151 /* UserSearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194F0222A6BA07001B3151 /* UserSearchView.swift */; }; + 6B194F0322A6BA07001B3151 /* SearchUserView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194F0222A6BA07001B3151 /* SearchUserView.swift */; }; 6B194F0522A6BA08001B3151 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6B194F0422A6BA08001B3151 /* Assets.xcassets */; }; 6B194F0822A6BA08001B3151 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6B194F0722A6BA08001B3151 /* Preview Assets.xcassets */; }; 6B194F0B22A6BA08001B3151 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6B194F0922A6BA08001B3151 /* LaunchScreen.storyboard */; }; - 6B194F1322A7108C001B3151 /* UserRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194F1222A7108C001B3151 /* UserRow.swift */; }; + 6B194F1322A7108C001B3151 /* SearchUserRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194F1222A7108C001B3151 /* SearchUserRow.swift */; }; 6B194F1522A710AB001B3151 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194F1422A710AB001B3151 /* User.swift */; }; 6B194F1722A710E6001B3151 /* SearchUserResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194F1622A710E6001B3151 /* SearchUserResponse.swift */; }; 6B194F1922A710FF001B3151 /* SearchUserViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194F1822A710FF001B3151 /* SearchUserViewModel.swift */; }; - 6B194F1B22A7112D001B3151 /* UserSearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194F1A22A7112D001B3151 /* UserSearchBar.swift */; }; + 6B194F1B22A7112D001B3151 /* SearchUserBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194F1A22A7112D001B3151 /* SearchUserBar.swift */; }; 6B194F1D22A71154001B3151 /* FoundationExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194F1C22A71154001B3151 /* FoundationExtensions.swift */; }; 6B194F1F22A71B0F001B3151 /* AnySubscription.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B194F1E22A71B0F001B3151 /* AnySubscription.swift */; }; /* End PBXBuildFile section */ @@ -26,16 +26,16 @@ 6B194EFB22A6BA07001B3151 /* SwiftUI-Combine-Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "SwiftUI-Combine-Example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 6B194EFE22A6BA07001B3151 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 6B194F0022A6BA07001B3151 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; - 6B194F0222A6BA07001B3151 /* UserSearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSearchView.swift; sourceTree = ""; }; + 6B194F0222A6BA07001B3151 /* SearchUserView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchUserView.swift; sourceTree = ""; }; 6B194F0422A6BA08001B3151 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 6B194F0722A6BA08001B3151 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 6B194F0A22A6BA08001B3151 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 6B194F0C22A6BA08001B3151 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 6B194F1222A7108C001B3151 /* UserRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserRow.swift; sourceTree = ""; }; + 6B194F1222A7108C001B3151 /* SearchUserRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchUserRow.swift; sourceTree = ""; }; 6B194F1422A710AB001B3151 /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = ""; }; 6B194F1622A710E6001B3151 /* SearchUserResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchUserResponse.swift; sourceTree = ""; }; 6B194F1822A710FF001B3151 /* SearchUserViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchUserViewModel.swift; sourceTree = ""; }; - 6B194F1A22A7112D001B3151 /* UserSearchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSearchBar.swift; sourceTree = ""; }; + 6B194F1A22A7112D001B3151 /* SearchUserBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchUserBar.swift; sourceTree = ""; }; 6B194F1C22A71154001B3151 /* FoundationExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoundationExtensions.swift; sourceTree = ""; }; 6B194F1E22A71B0F001B3151 /* AnySubscription.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnySubscription.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -70,12 +70,12 @@ 6B194EFD22A6BA07001B3151 /* SwiftUI-Combine-Example */ = { isa = PBXGroup; children = ( - 6B194F0222A6BA07001B3151 /* UserSearchView.swift */, + 6B194F0222A6BA07001B3151 /* SearchUserView.swift */, 6B194F1822A710FF001B3151 /* SearchUserViewModel.swift */, - 6B194F1A22A7112D001B3151 /* UserSearchBar.swift */, - 6B194F1222A7108C001B3151 /* UserRow.swift */, - 6B194F1422A710AB001B3151 /* User.swift */, + 6B194F1A22A7112D001B3151 /* SearchUserBar.swift */, + 6B194F1222A7108C001B3151 /* SearchUserRow.swift */, 6B194F1622A710E6001B3151 /* SearchUserResponse.swift */, + 6B194F1422A710AB001B3151 /* User.swift */, 6B194F1E22A71B0F001B3151 /* AnySubscription.swift */, 6B194F1C22A71154001B3151 /* FoundationExtensions.swift */, 6B194F0022A6BA07001B3151 /* SceneDelegate.swift */, @@ -167,16 +167,16 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 6B194F1B22A7112D001B3151 /* UserSearchBar.swift in Sources */, + 6B194F1B22A7112D001B3151 /* SearchUserBar.swift in Sources */, 6B194EFF22A6BA07001B3151 /* AppDelegate.swift in Sources */, 6B194F0122A6BA07001B3151 /* SceneDelegate.swift in Sources */, 6B194F1F22A71B0F001B3151 /* AnySubscription.swift in Sources */, - 6B194F0322A6BA07001B3151 /* UserSearchView.swift in Sources */, + 6B194F0322A6BA07001B3151 /* SearchUserView.swift in Sources */, 6B194F1922A710FF001B3151 /* SearchUserViewModel.swift in Sources */, 6B194F1722A710E6001B3151 /* SearchUserResponse.swift in Sources */, 6B194F1D22A71154001B3151 /* FoundationExtensions.swift in Sources */, 6B194F1522A710AB001B3151 /* User.swift in Sources */, - 6B194F1322A7108C001B3151 /* UserRow.swift in Sources */, + 6B194F1322A7108C001B3151 /* SearchUserRow.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/SwiftUI-Combine-Example/SceneDelegate.swift b/SwiftUI-Combine-Example/SceneDelegate.swift index 95a7c05..f41d993 100644 --- a/SwiftUI-Combine-Example/SceneDelegate.swift +++ b/SwiftUI-Combine-Example/SceneDelegate.swift @@ -7,7 +7,7 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate { func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { let window = UIWindow(frame: UIScreen.main.bounds) window.rootViewController = UIHostingController( - rootView: UserSearchView().environmentObject(SearchUserViewModel()) + rootView: SearchUserView().environmentObject(SearchUserViewModel()) ) self.window = window window.makeKeyAndVisible() diff --git a/SwiftUI-Combine-Example/UserSearchBar.swift b/SwiftUI-Combine-Example/SearchUserBar.swift similarity index 96% rename from SwiftUI-Combine-Example/UserSearchBar.swift rename to SwiftUI-Combine-Example/SearchUserBar.swift index 179a4a8..73f327b 100644 --- a/SwiftUI-Combine-Example/UserSearchBar.swift +++ b/SwiftUI-Combine-Example/SearchUserBar.swift @@ -1,6 +1,6 @@ import SwiftUI -struct UserSearchBar: View { +struct SearchUserBar: View { @Binding var text: String @State var action: () -> Void diff --git a/SwiftUI-Combine-Example/UserRow.swift b/SwiftUI-Combine-Example/SearchUserRow.swift similarity index 96% rename from SwiftUI-Combine-Example/UserRow.swift rename to SwiftUI-Combine-Example/SearchUserRow.swift index 4ee3a3e..08be368 100644 --- a/SwiftUI-Combine-Example/UserRow.swift +++ b/SwiftUI-Combine-Example/SearchUserRow.swift @@ -1,6 +1,6 @@ import SwiftUI -struct UserRow: View { +struct SearchUserRow: View { @EnvironmentObject var viewModel: SearchUserViewModel @State var user: User @@ -13,8 +13,10 @@ struct UserRow: View { .clipShape(Circle()) .overlay(Circle().stroke(Color.gray, lineWidth: 1)) } + Text(user.login) .font(Font.system(size: 18).bold()) + Spacer() } .padding(EdgeInsets(top: 8, leading: 16, bottom: 8, trailing: 16)) diff --git a/SwiftUI-Combine-Example/UserSearchView.swift b/SwiftUI-Combine-Example/SearchUserView.swift similarity index 79% rename from SwiftUI-Combine-Example/UserSearchView.swift rename to SwiftUI-Combine-Example/SearchUserView.swift index 649cab4..8ae5044 100644 --- a/SwiftUI-Combine-Example/UserSearchView.swift +++ b/SwiftUI-Combine-Example/SearchUserView.swift @@ -1,18 +1,18 @@ import SwiftUI -struct UserSearchView: View { +struct SearchUserView: View { @EnvironmentObject var viewModel: SearchUserViewModel @State var text = "ra1028" var body: some View { NavigationView { VStack { - UserSearchBar(text: $text) { + SearchUserBar(text: $text) { self.viewModel.search(name: self.text) } List(viewModel.users) { user in - UserRow(user: user) + SearchUserRow(user: user) .tapAction { print(user) } } }