├── .gitignore ├── LICENSE ├── README.md ├── Rambafile ├── Routing.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── WorkspaceSettings.xcsettings ├── Routing.xcworkspace ├── contents.xcworkspacedata └── xcshareddata │ └── WorkspaceSettings.xcsettings ├── Routing ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ └── LaunchScreen.storyboard ├── FadeAnimator.swift ├── Info.plist ├── Main │ ├── MainModuleBuilder.swift │ ├── MainRouter.swift │ ├── MainViewController.swift │ └── MainViewModel.swift ├── Routing │ ├── Animator.swift │ ├── Router.swift │ ├── Routes │ │ ├── AppSettingsRoute.swift │ │ ├── NoInternetConnectionRoute.swift │ │ └── SettingsRoute.swift │ └── Transitions │ │ ├── ModalTransition.swift │ │ ├── PushTransition.swift │ │ └── Transition.swift └── Settings │ ├── SettingsModule.swift │ ├── SettingsRouter.swift │ ├── SettingsViewController.swift │ └── SettingsViewModel.swift └── Templates ├── rsb_swift_service ├── Code │ ├── service.swift.liquid │ └── service_protocol.swift.liquid ├── rsb_swift_service.rambaspec └── snippets │ └── header.liquid └── rsb_swift_viper_vm_di_module ├── Code ├── ModuleBuilder.swift.liquid ├── Router.swift.liquid ├── ViewController.swift.liquid └── ViewModel.swift.liquid ├── rsb_swift_viper_vm_di_module.rambaspec └── snippets └── header.liquid /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | # Packages/ 39 | # Package.pins 40 | .build/ 41 | 42 | # CocoaPods 43 | # 44 | # We recommend against adding the Pods directory to your .gitignore. However 45 | # you should judge for yourself, the pros and cons are mentioned at: 46 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 47 | # 48 | # Pods/ 49 | 50 | # Carthage 51 | # 52 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 53 | # Carthage/Checkouts 54 | 55 | Carthage/Build 56 | 57 | # fastlane 58 | # 59 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 60 | # screenshots whenever they are needed. 61 | # For more information about the recommended setup visit: 62 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 63 | 64 | fastlane/report.xml 65 | fastlane/Preview.html 66 | fastlane/screenshots 67 | fastlane/test_output 68 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Nikita Ermolenko 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Routing 2 | A Flexible Routing Approach in an iOS App 3 | 4 | At [Rosberry](http://about.rosberry.com) we’ve refused using storyboards, except the Launch Screen of course and configure all layout and transition logic in code. In order to understand our reasons — read the [Life without Interface Builder](https://blog.zeplin.io/life-without-interface-builder-adbb009d2068) written by Zeplin’s team, I hope you will find this post useful! 5 | In this article, I’m going to introduce a new approach to routing between view controllers. We’ll start with a problem and step by step will come to a final decision. 6 | 7 | ... continue reading on [Medium](https://medium.com/rosberryapps/the-flexible-routing-approach-in-an-ios-app-eb4b05aa7f52)! 8 | -------------------------------------------------------------------------------- /Rambafile: -------------------------------------------------------------------------------- 1 | ### Headers settings 2 | company: Rosberry 3 | 4 | ### Xcode project settings 5 | project_name: Routing 6 | xcodeproj_path: Routing.xcodeproj 7 | 8 | ### Code generation settings section 9 | # The main project target name 10 | project_target: Routing 11 | 12 | # The file path for new modules 13 | project_file_path: Routing/ 14 | 15 | # The xcodeproje group path to new modules 16 | project_group_path: Routing/ 17 | 18 | ### Templates 19 | catalogs: 20 | - 'https://github.com/rosberry/Rosberry-Generamba-Templates.git' 21 | 22 | templates: 23 | - {name: rsb_swift_viper_vm_di_module} 24 | - {name: rsb_swift_service} 25 | -------------------------------------------------------------------------------- /Routing.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 480AAE2A0C9B4FB762DC916C /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3584C57ADCB7E2E7C56A987 /* SettingsViewController.swift */; }; 11 | 7981634FCCC7A63B9E29CE17 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C421D5F891ABB347B417A484 /* MainViewController.swift */; }; 12 | 840F1AF81F7E25B900FF3A4E /* FadeAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 840F1AF71F7E25B900FF3A4E /* FadeAnimator.swift */; }; 13 | 8420708A1F7BB2B400C84CAC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842070891F7BB2B400C84CAC /* AppDelegate.swift */; }; 14 | 842070911F7BB2B400C84CAC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 842070901F7BB2B400C84CAC /* Assets.xcassets */; }; 15 | 842070941F7BB2B400C84CAC /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 842070921F7BB2B400C84CAC /* LaunchScreen.storyboard */; }; 16 | 847611281F7E3D230018FA76 /* AppSettingsRoute.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847611271F7E3D230018FA76 /* AppSettingsRoute.swift */; }; 17 | 848E860D1FA4C10100B35054 /* PushTransition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 848E860C1FA4C10100B35054 /* PushTransition.swift */; }; 18 | 848E860F1FA4C1A100B35054 /* ModalTransition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 848E860E1FA4C1A100B35054 /* ModalTransition.swift */; }; 19 | 848E86121FA4C25800B35054 /* Animator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 848E86101FA4C22800B35054 /* Animator.swift */; }; 20 | 848E86141FA4C27100B35054 /* Transition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 840F1AF91F7E30AE00FF3A4E /* Transition.swift */; }; 21 | 84A1E1B91F7E183400D6F48A /* NoInternetConnectionRoute.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A1E1B81F7E183400D6F48A /* NoInternetConnectionRoute.swift */; }; 22 | 84A1E1BB1F7E185D00D6F48A /* SettingsRoute.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A1E1BA1F7E185D00D6F48A /* SettingsRoute.swift */; }; 23 | 84D1B9651F7E16AF00A03C7F /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D1B9641F7E16AF00A03C7F /* Router.swift */; }; 24 | 9E09C5DEB69CC12624D12409 /* MainViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2275081B8B4BE0858F0F0E17 /* MainViewModel.swift */; }; 25 | B4B1F209862D2AF71AC97768 /* MainRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = E59270DD4AADFF771D2867BA /* MainRouter.swift */; }; 26 | C2CC82C233307AE3FDE79111 /* SettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4487447FB0A7A85008D0B3DF /* SettingsViewModel.swift */; }; 27 | CF27C648698108F7E41C1851 /* SettingsRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8FB72E0B38DCE97871A4986 /* SettingsRouter.swift */; }; 28 | E768606C89EACC029EB14A59 /* SettingsModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95AEB56EC18E4BE561F783E1 /* SettingsModule.swift */; }; 29 | F815D882C2DF079E6A7F16ED /* MainModuleBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7475DB17584D6CF14332771 /* MainModuleBuilder.swift */; }; 30 | /* End PBXBuildFile section */ 31 | 32 | /* Begin PBXFileReference section */ 33 | 2275081B8B4BE0858F0F0E17 /* MainViewModel.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = MainViewModel.swift; sourceTree = ""; }; 34 | 4487447FB0A7A85008D0B3DF /* SettingsViewModel.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = SettingsViewModel.swift; sourceTree = ""; }; 35 | 840F1AF71F7E25B900FF3A4E /* FadeAnimator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FadeAnimator.swift; sourceTree = ""; }; 36 | 840F1AF91F7E30AE00FF3A4E /* Transition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Transition.swift; sourceTree = ""; }; 37 | 842070861F7BB2B400C84CAC /* Routing.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Routing.app; sourceTree = BUILT_PRODUCTS_DIR; }; 38 | 842070891F7BB2B400C84CAC /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 39 | 842070901F7BB2B400C84CAC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 40 | 842070931F7BB2B400C84CAC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 41 | 842070951F7BB2B400C84CAC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 42 | 847611271F7E3D230018FA76 /* AppSettingsRoute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppSettingsRoute.swift; sourceTree = ""; }; 43 | 848E860C1FA4C10100B35054 /* PushTransition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushTransition.swift; sourceTree = ""; }; 44 | 848E860E1FA4C1A100B35054 /* ModalTransition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalTransition.swift; sourceTree = ""; }; 45 | 848E86101FA4C22800B35054 /* Animator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Animator.swift; sourceTree = ""; }; 46 | 84A1E1B81F7E183400D6F48A /* NoInternetConnectionRoute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoInternetConnectionRoute.swift; sourceTree = ""; }; 47 | 84A1E1BA1F7E185D00D6F48A /* SettingsRoute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsRoute.swift; sourceTree = ""; }; 48 | 84D1B9641F7E16AF00A03C7F /* Router.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = ""; }; 49 | 95AEB56EC18E4BE561F783E1 /* SettingsModule.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = SettingsModule.swift; sourceTree = ""; }; 50 | A3584C57ADCB7E2E7C56A987 /* SettingsViewController.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = ""; }; 51 | A7475DB17584D6CF14332771 /* MainModuleBuilder.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = MainModuleBuilder.swift; sourceTree = ""; }; 52 | C421D5F891ABB347B417A484 /* MainViewController.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = ""; }; 53 | D8FB72E0B38DCE97871A4986 /* SettingsRouter.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = SettingsRouter.swift; sourceTree = ""; }; 54 | E59270DD4AADFF771D2867BA /* MainRouter.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = MainRouter.swift; sourceTree = ""; }; 55 | /* End PBXFileReference section */ 56 | 57 | /* Begin PBXFrameworksBuildPhase section */ 58 | 842070831F7BB2B400C84CAC /* Frameworks */ = { 59 | isa = PBXFrameworksBuildPhase; 60 | buildActionMask = 2147483647; 61 | files = ( 62 | ); 63 | runOnlyForDeploymentPostprocessing = 0; 64 | }; 65 | /* End PBXFrameworksBuildPhase section */ 66 | 67 | /* Begin PBXGroup section */ 68 | 8409249F1F7BB5E600F88986 /* Routing */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | 84D1B9641F7E16AF00A03C7F /* Router.swift */, 72 | 848E86101FA4C22800B35054 /* Animator.swift */, 73 | 848E860A1FA4C0BA00B35054 /* Transitions */, 74 | 84A1E1B51F7E17AE00D6F48A /* Routes */, 75 | ); 76 | path = Routing; 77 | sourceTree = ""; 78 | }; 79 | 8420707D1F7BB2B400C84CAC = { 80 | isa = PBXGroup; 81 | children = ( 82 | 842070881F7BB2B400C84CAC /* Routing */, 83 | 842070871F7BB2B400C84CAC /* Products */, 84 | ); 85 | sourceTree = ""; 86 | }; 87 | 842070871F7BB2B400C84CAC /* Products */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | 842070861F7BB2B400C84CAC /* Routing.app */, 91 | ); 92 | name = Products; 93 | sourceTree = ""; 94 | }; 95 | 842070881F7BB2B400C84CAC /* Routing */ = { 96 | isa = PBXGroup; 97 | children = ( 98 | 842070891F7BB2B400C84CAC /* AppDelegate.swift */, 99 | 842070901F7BB2B400C84CAC /* Assets.xcassets */, 100 | 842070921F7BB2B400C84CAC /* LaunchScreen.storyboard */, 101 | 842070951F7BB2B400C84CAC /* Info.plist */, 102 | 840F1AF71F7E25B900FF3A4E /* FadeAnimator.swift */, 103 | 8409249F1F7BB5E600F88986 /* Routing */, 104 | FDF8CC0E3159594959DF7E87 /* Settings */, 105 | F1835268A855DA6007376E00 /* Main */, 106 | ); 107 | path = Routing; 108 | sourceTree = ""; 109 | }; 110 | 848E860A1FA4C0BA00B35054 /* Transitions */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | 840F1AF91F7E30AE00FF3A4E /* Transition.swift */, 114 | 848E860C1FA4C10100B35054 /* PushTransition.swift */, 115 | 848E860E1FA4C1A100B35054 /* ModalTransition.swift */, 116 | ); 117 | path = Transitions; 118 | sourceTree = ""; 119 | }; 120 | 84A1E1B51F7E17AE00D6F48A /* Routes */ = { 121 | isa = PBXGroup; 122 | children = ( 123 | 84A1E1B81F7E183400D6F48A /* NoInternetConnectionRoute.swift */, 124 | 84A1E1BA1F7E185D00D6F48A /* SettingsRoute.swift */, 125 | 847611271F7E3D230018FA76 /* AppSettingsRoute.swift */, 126 | ); 127 | path = Routes; 128 | sourceTree = ""; 129 | }; 130 | F1835268A855DA6007376E00 /* Main */ = { 131 | isa = PBXGroup; 132 | children = ( 133 | A7475DB17584D6CF14332771 /* MainModuleBuilder.swift */, 134 | C421D5F891ABB347B417A484 /* MainViewController.swift */, 135 | 2275081B8B4BE0858F0F0E17 /* MainViewModel.swift */, 136 | E59270DD4AADFF771D2867BA /* MainRouter.swift */, 137 | ); 138 | path = Main; 139 | sourceTree = ""; 140 | }; 141 | FDF8CC0E3159594959DF7E87 /* Settings */ = { 142 | isa = PBXGroup; 143 | children = ( 144 | 95AEB56EC18E4BE561F783E1 /* SettingsModule.swift */, 145 | A3584C57ADCB7E2E7C56A987 /* SettingsViewController.swift */, 146 | 4487447FB0A7A85008D0B3DF /* SettingsViewModel.swift */, 147 | D8FB72E0B38DCE97871A4986 /* SettingsRouter.swift */, 148 | ); 149 | path = Settings; 150 | sourceTree = ""; 151 | }; 152 | /* End PBXGroup section */ 153 | 154 | /* Begin PBXNativeTarget section */ 155 | 842070851F7BB2B400C84CAC /* Routing */ = { 156 | isa = PBXNativeTarget; 157 | buildConfigurationList = 842070981F7BB2B400C84CAC /* Build configuration list for PBXNativeTarget "Routing" */; 158 | buildPhases = ( 159 | 842070821F7BB2B400C84CAC /* Sources */, 160 | 842070831F7BB2B400C84CAC /* Frameworks */, 161 | 842070841F7BB2B400C84CAC /* Resources */, 162 | ); 163 | buildRules = ( 164 | ); 165 | dependencies = ( 166 | ); 167 | name = Routing; 168 | productName = Routing; 169 | productReference = 842070861F7BB2B400C84CAC /* Routing.app */; 170 | productType = "com.apple.product-type.application"; 171 | }; 172 | /* End PBXNativeTarget section */ 173 | 174 | /* Begin PBXProject section */ 175 | 8420707E1F7BB2B400C84CAC /* Project object */ = { 176 | isa = PBXProject; 177 | attributes = { 178 | LastSwiftUpdateCheck = 0900; 179 | LastUpgradeCheck = 0900; 180 | TargetAttributes = { 181 | 842070851F7BB2B400C84CAC = { 182 | CreatedOnToolsVersion = 9.0; 183 | ProvisioningStyle = Manual; 184 | }; 185 | }; 186 | }; 187 | buildConfigurationList = 842070811F7BB2B400C84CAC /* Build configuration list for PBXProject "Routing" */; 188 | compatibilityVersion = "Xcode 8.0"; 189 | developmentRegion = en; 190 | hasScannedForEncodings = 0; 191 | knownRegions = ( 192 | en, 193 | Base, 194 | ); 195 | mainGroup = 8420707D1F7BB2B400C84CAC; 196 | productRefGroup = 842070871F7BB2B400C84CAC /* Products */; 197 | projectDirPath = ""; 198 | projectRoot = ""; 199 | targets = ( 200 | 842070851F7BB2B400C84CAC /* Routing */, 201 | ); 202 | }; 203 | /* End PBXProject section */ 204 | 205 | /* Begin PBXResourcesBuildPhase section */ 206 | 842070841F7BB2B400C84CAC /* Resources */ = { 207 | isa = PBXResourcesBuildPhase; 208 | buildActionMask = 2147483647; 209 | files = ( 210 | 842070941F7BB2B400C84CAC /* LaunchScreen.storyboard in Resources */, 211 | 842070911F7BB2B400C84CAC /* Assets.xcassets in Resources */, 212 | ); 213 | runOnlyForDeploymentPostprocessing = 0; 214 | }; 215 | /* End PBXResourcesBuildPhase section */ 216 | 217 | /* Begin PBXSourcesBuildPhase section */ 218 | 842070821F7BB2B400C84CAC /* Sources */ = { 219 | isa = PBXSourcesBuildPhase; 220 | buildActionMask = 2147483647; 221 | files = ( 222 | 8420708A1F7BB2B400C84CAC /* AppDelegate.swift in Sources */, 223 | 847611281F7E3D230018FA76 /* AppSettingsRoute.swift in Sources */, 224 | E768606C89EACC029EB14A59 /* SettingsModule.swift in Sources */, 225 | 840F1AF81F7E25B900FF3A4E /* FadeAnimator.swift in Sources */, 226 | 84A1E1BB1F7E185D00D6F48A /* SettingsRoute.swift in Sources */, 227 | 480AAE2A0C9B4FB762DC916C /* SettingsViewController.swift in Sources */, 228 | C2CC82C233307AE3FDE79111 /* SettingsViewModel.swift in Sources */, 229 | CF27C648698108F7E41C1851 /* SettingsRouter.swift in Sources */, 230 | F815D882C2DF079E6A7F16ED /* MainModuleBuilder.swift in Sources */, 231 | 84D1B9651F7E16AF00A03C7F /* Router.swift in Sources */, 232 | 848E860D1FA4C10100B35054 /* PushTransition.swift in Sources */, 233 | 7981634FCCC7A63B9E29CE17 /* MainViewController.swift in Sources */, 234 | 848E860F1FA4C1A100B35054 /* ModalTransition.swift in Sources */, 235 | 9E09C5DEB69CC12624D12409 /* MainViewModel.swift in Sources */, 236 | B4B1F209862D2AF71AC97768 /* MainRouter.swift in Sources */, 237 | 848E86141FA4C27100B35054 /* Transition.swift in Sources */, 238 | 84A1E1B91F7E183400D6F48A /* NoInternetConnectionRoute.swift in Sources */, 239 | 848E86121FA4C25800B35054 /* Animator.swift in Sources */, 240 | ); 241 | runOnlyForDeploymentPostprocessing = 0; 242 | }; 243 | /* End PBXSourcesBuildPhase section */ 244 | 245 | /* Begin PBXVariantGroup section */ 246 | 842070921F7BB2B400C84CAC /* LaunchScreen.storyboard */ = { 247 | isa = PBXVariantGroup; 248 | children = ( 249 | 842070931F7BB2B400C84CAC /* Base */, 250 | ); 251 | name = LaunchScreen.storyboard; 252 | sourceTree = ""; 253 | }; 254 | /* End PBXVariantGroup section */ 255 | 256 | /* Begin XCBuildConfiguration section */ 257 | 842070961F7BB2B400C84CAC /* Debug */ = { 258 | isa = XCBuildConfiguration; 259 | buildSettings = { 260 | ALWAYS_SEARCH_USER_PATHS = NO; 261 | CLANG_ANALYZER_NONNULL = YES; 262 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 263 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 264 | CLANG_CXX_LIBRARY = "libc++"; 265 | CLANG_ENABLE_MODULES = YES; 266 | CLANG_ENABLE_OBJC_ARC = YES; 267 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 268 | CLANG_WARN_BOOL_CONVERSION = YES; 269 | CLANG_WARN_COMMA = YES; 270 | CLANG_WARN_CONSTANT_CONVERSION = YES; 271 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 272 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 273 | CLANG_WARN_EMPTY_BODY = YES; 274 | CLANG_WARN_ENUM_CONVERSION = YES; 275 | CLANG_WARN_INFINITE_RECURSION = YES; 276 | CLANG_WARN_INT_CONVERSION = YES; 277 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 278 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 279 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 280 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 281 | CLANG_WARN_STRICT_PROTOTYPES = YES; 282 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 283 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 284 | CLANG_WARN_UNREACHABLE_CODE = YES; 285 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 286 | CODE_SIGN_IDENTITY = "iPhone Developer"; 287 | COPY_PHASE_STRIP = NO; 288 | DEBUG_INFORMATION_FORMAT = dwarf; 289 | ENABLE_STRICT_OBJC_MSGSEND = YES; 290 | ENABLE_TESTABILITY = YES; 291 | GCC_C_LANGUAGE_STANDARD = gnu11; 292 | GCC_DYNAMIC_NO_PIC = NO; 293 | GCC_NO_COMMON_BLOCKS = YES; 294 | GCC_OPTIMIZATION_LEVEL = 0; 295 | GCC_PREPROCESSOR_DEFINITIONS = ( 296 | "DEBUG=1", 297 | "$(inherited)", 298 | ); 299 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 300 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 301 | GCC_WARN_UNDECLARED_SELECTOR = YES; 302 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 303 | GCC_WARN_UNUSED_FUNCTION = YES; 304 | GCC_WARN_UNUSED_VARIABLE = YES; 305 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 306 | MTL_ENABLE_DEBUG_INFO = YES; 307 | ONLY_ACTIVE_ARCH = YES; 308 | SDKROOT = iphoneos; 309 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 310 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 311 | }; 312 | name = Debug; 313 | }; 314 | 842070971F7BB2B400C84CAC /* Release */ = { 315 | isa = XCBuildConfiguration; 316 | buildSettings = { 317 | ALWAYS_SEARCH_USER_PATHS = NO; 318 | CLANG_ANALYZER_NONNULL = YES; 319 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 320 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 321 | CLANG_CXX_LIBRARY = "libc++"; 322 | CLANG_ENABLE_MODULES = YES; 323 | CLANG_ENABLE_OBJC_ARC = YES; 324 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 325 | CLANG_WARN_BOOL_CONVERSION = YES; 326 | CLANG_WARN_COMMA = YES; 327 | CLANG_WARN_CONSTANT_CONVERSION = YES; 328 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 329 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 330 | CLANG_WARN_EMPTY_BODY = YES; 331 | CLANG_WARN_ENUM_CONVERSION = YES; 332 | CLANG_WARN_INFINITE_RECURSION = YES; 333 | CLANG_WARN_INT_CONVERSION = YES; 334 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 335 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 336 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 337 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 338 | CLANG_WARN_STRICT_PROTOTYPES = YES; 339 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 340 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 341 | CLANG_WARN_UNREACHABLE_CODE = YES; 342 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 343 | CODE_SIGN_IDENTITY = "iPhone Developer"; 344 | COPY_PHASE_STRIP = NO; 345 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 346 | ENABLE_NS_ASSERTIONS = NO; 347 | ENABLE_STRICT_OBJC_MSGSEND = YES; 348 | GCC_C_LANGUAGE_STANDARD = gnu11; 349 | GCC_NO_COMMON_BLOCKS = YES; 350 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 351 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 352 | GCC_WARN_UNDECLARED_SELECTOR = YES; 353 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 354 | GCC_WARN_UNUSED_FUNCTION = YES; 355 | GCC_WARN_UNUSED_VARIABLE = YES; 356 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 357 | MTL_ENABLE_DEBUG_INFO = NO; 358 | SDKROOT = iphoneos; 359 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 360 | VALIDATE_PRODUCT = YES; 361 | }; 362 | name = Release; 363 | }; 364 | 842070991F7BB2B400C84CAC /* Debug */ = { 365 | isa = XCBuildConfiguration; 366 | buildSettings = { 367 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 368 | CODE_SIGN_STYLE = Manual; 369 | DEVELOPMENT_TEAM = GPVA8JVMU3; 370 | INFOPLIST_FILE = Routing/Info.plist; 371 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 372 | PRODUCT_BUNDLE_IDENTIFIER = com.nikita.Routing; 373 | PRODUCT_NAME = "$(TARGET_NAME)"; 374 | PROVISIONING_PROFILE = "b600a559-bce8-4b59-a920-97187ecab1e0"; 375 | PROVISIONING_PROFILE_SPECIFIER = RosberryDev; 376 | SWIFT_VERSION = 4.0; 377 | TARGETED_DEVICE_FAMILY = "1,2"; 378 | }; 379 | name = Debug; 380 | }; 381 | 8420709A1F7BB2B400C84CAC /* Release */ = { 382 | isa = XCBuildConfiguration; 383 | buildSettings = { 384 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 385 | CODE_SIGN_STYLE = Manual; 386 | DEVELOPMENT_TEAM = ""; 387 | INFOPLIST_FILE = Routing/Info.plist; 388 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 389 | PRODUCT_BUNDLE_IDENTIFIER = com.nikita.Routing; 390 | PRODUCT_NAME = "$(TARGET_NAME)"; 391 | PROVISIONING_PROFILE_SPECIFIER = ""; 392 | SWIFT_VERSION = 4.0; 393 | TARGETED_DEVICE_FAMILY = "1,2"; 394 | }; 395 | name = Release; 396 | }; 397 | /* End XCBuildConfiguration section */ 398 | 399 | /* Begin XCConfigurationList section */ 400 | 842070811F7BB2B400C84CAC /* Build configuration list for PBXProject "Routing" */ = { 401 | isa = XCConfigurationList; 402 | buildConfigurations = ( 403 | 842070961F7BB2B400C84CAC /* Debug */, 404 | 842070971F7BB2B400C84CAC /* Release */, 405 | ); 406 | defaultConfigurationIsVisible = 0; 407 | defaultConfigurationName = Release; 408 | }; 409 | 842070981F7BB2B400C84CAC /* Build configuration list for PBXNativeTarget "Routing" */ = { 410 | isa = XCConfigurationList; 411 | buildConfigurations = ( 412 | 842070991F7BB2B400C84CAC /* Debug */, 413 | 8420709A1F7BB2B400C84CAC /* Release */, 414 | ); 415 | defaultConfigurationIsVisible = 0; 416 | defaultConfigurationName = Release; 417 | }; 418 | /* End XCConfigurationList section */ 419 | }; 420 | rootObject = 8420707E1F7BB2B400C84CAC /* Project object */; 421 | } 422 | -------------------------------------------------------------------------------- /Routing.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Routing.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildSystemType 6 | Latest 7 | 8 | 9 | -------------------------------------------------------------------------------- /Routing.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Routing.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildSystemType 6 | Latest 7 | 8 | 9 | -------------------------------------------------------------------------------- /Routing/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Routing 4 | // 5 | // Created by Nikita Ermolenko on 27/09/2017. 6 | // 7 | 8 | import UIKit 9 | 10 | @UIApplicationMain 11 | class AppDelegate: UIResponder, UIApplicationDelegate { 12 | 13 | var window: UIWindow? 14 | 15 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 16 | let mainModule = MainModuleBuilder.module() 17 | let navigationController = UINavigationController(rootViewController: mainModule) 18 | 19 | window = UIWindow(frame: UIScreen.main.bounds) 20 | window?.rootViewController = navigationController 21 | window?.makeKeyAndVisible() 22 | 23 | return true 24 | } 25 | 26 | func applicationWillResignActive(_ application: UIApplication) { 27 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 28 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 29 | } 30 | 31 | func applicationDidEnterBackground(_ application: UIApplication) { 32 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 33 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 34 | } 35 | 36 | func applicationWillEnterForeground(_ application: UIApplication) { 37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 38 | } 39 | 40 | func applicationDidBecomeActive(_ application: UIApplication) { 41 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 42 | } 43 | 44 | func applicationWillTerminate(_ application: UIApplication) { 45 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 46 | } 47 | 48 | 49 | } 50 | 51 | -------------------------------------------------------------------------------- /Routing/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | } 88 | ], 89 | "info" : { 90 | "version" : 1, 91 | "author" : "xcode" 92 | } 93 | } -------------------------------------------------------------------------------- /Routing/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Routing/FadeAnimator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FadeAnimator.swift 3 | // Routing 4 | // 5 | // Created by Nikita Ermolenko on 29/09/2017. 6 | // 7 | 8 | import Foundation 9 | import UIKit 10 | 11 | final class FadeAnimator: NSObject, Animator { 12 | 13 | var isPresenting: Bool = true 14 | 15 | func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { 16 | return 0.4 17 | } 18 | 19 | func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { 20 | if isPresenting { 21 | present(using: transitionContext) 22 | } 23 | else { 24 | dismiss(using: transitionContext) 25 | } 26 | } 27 | 28 | private func present(using transitionContext: UIViewControllerContextTransitioning) { 29 | guard let toViewController = transitionContext.viewController(forKey: .to) else { 30 | return 31 | } 32 | 33 | let containerView = transitionContext.containerView 34 | toViewController.view.alpha = 0 35 | containerView.addSubview(toViewController.view) 36 | 37 | UIView.animate(withDuration: transitionDuration(using: transitionContext), animations: { 38 | toViewController.view.alpha = 1.0 39 | }, completion: { _ in 40 | transitionContext.completeTransition(true) 41 | }) 42 | } 43 | 44 | private func dismiss(using transitionContext: UIViewControllerContextTransitioning) { 45 | guard let toViewController = transitionContext.viewController(forKey: .to) else { 46 | return 47 | } 48 | guard let fromViewController = transitionContext.viewController(forKey: .from) else { 49 | return 50 | } 51 | 52 | let containerView = transitionContext.containerView 53 | containerView.addSubview(toViewController.view) 54 | containerView.addSubview(fromViewController.view) 55 | 56 | UIView.animate(withDuration: transitionDuration(using: transitionContext), animations: { 57 | fromViewController.view.alpha = 0.0 58 | }, completion: { _ in 59 | transitionContext.completeTransition(true) 60 | }) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Routing/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIRequiredDeviceCapabilities 26 | 27 | armv7 28 | 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | UISupportedInterfaceOrientations~ipad 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationPortraitUpsideDown 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Routing/Main/MainModuleBuilder.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MainModuleBuilder.swift 3 | // Routing 4 | // 5 | // Created by Nikita Ermolenko on 27/09/2017. 6 | // Copyright © 2017 Rosberry. All rights reserved. 7 | // 8 | 9 | final class MainModuleBuilder { 10 | 11 | static func module() -> MainViewController { 12 | let router = MainRouter() 13 | let viewModel = MainViewModel(router: router) 14 | let viewController = MainViewController(viewModel: viewModel) 15 | router.viewController = viewController 16 | return viewController 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Routing/Main/MainRouter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MainRouter.swift 3 | // Routing 4 | // 5 | // Created by Nikita Ermolenko on 27/09/2017. 6 | // Copyright © 2017 Rosberry. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | final class MainRouter: Router, MainRouter.Routes { 13 | 14 | typealias Routes = SettingsRoute & NoInternetConnectionRoute & AppSettingsRoute 15 | 16 | var settingsTransition: Transition { 17 | switch selectedIndex { 18 | case 0: return PushTransition() 19 | case 1: return ModalTransition() 20 | case 2: return ModalTransition(animator: FadeAnimator()) 21 | case 3: return PushTransition(animator: FadeAnimator()) 22 | default: return PushTransition() 23 | } 24 | } 25 | 26 | private var selectedIndex: Int { 27 | return UserDefaults.standard.value(forKey: "index") as? Int ?? 0 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Routing/Main/MainViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MainViewController.swift 3 | // Routing 4 | // 5 | // Created by Nikita Ermolenko on 27/09/2017. 6 | // Copyright © 2017 Rosberry. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | final class MainViewController: UIViewController { 12 | 13 | let viewModel: MainViewModel 14 | 15 | private lazy var segmentedControl: UISegmentedControl = { 16 | let segmentedControl = UISegmentedControl(items: ["push", "modal", "modal(custom)", "push(custom)"]) 17 | segmentedControl.addTarget(self, action: #selector(segmentedControlValueChanged), for: .valueChanged) 18 | segmentedControl.backgroundColor = .green 19 | return segmentedControl 20 | }() 21 | 22 | private lazy var settingsButton: UIButton = { 23 | let button = UIButton() 24 | button.backgroundColor = .red 25 | button.setTitle("Settings", for: .normal) 26 | button.addTarget(self, action: #selector(settingsButtonPressed), for: .touchUpInside) 27 | return button 28 | }() 29 | 30 | // MARK: - Lifecycle 31 | 32 | init(viewModel: MainViewModel) { 33 | self.viewModel = viewModel 34 | super.init(nibName: nil, bundle: nil) 35 | } 36 | 37 | required init?(coder aDecoder: NSCoder) { 38 | fatalError("init(coder:) has not been implemented") 39 | } 40 | 41 | override func viewDidLoad() { 42 | super.viewDidLoad() 43 | view.backgroundColor = .white 44 | view.addSubview(settingsButton) 45 | view.addSubview(segmentedControl) 46 | } 47 | 48 | override func viewDidLayoutSubviews() { 49 | super.viewDidLayoutSubviews() 50 | 51 | segmentedControl.frame = CGRect(x: 0, y: 60, width: 320, height: 50) 52 | 53 | settingsButton.frame.size = CGSize(width: 100, height: 50) 54 | settingsButton.center = view.center 55 | } 56 | 57 | // MARK: - Actions 58 | 59 | @objc private func settingsButtonPressed(_ sender: UIButton) { 60 | viewModel.didTriggerSettingsEvent() 61 | } 62 | 63 | @objc private func segmentedControlValueChanged(_ sender: UISegmentedControl) { 64 | UserDefaults.standard.setValue(sender.selectedSegmentIndex, forKey: "index") 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Routing/Main/MainViewModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MainViewModel.swift 3 | // Routing 4 | // 5 | // Created by Nikita Ermolenko on 27/09/2017. 6 | // Copyright © 2017 Rosberry. All rights reserved. 7 | // 8 | 9 | class MainViewModel { 10 | 11 | private let router: MainRouter.Routes 12 | 13 | init(router: MainRouter.Routes) { 14 | self.router = router 15 | } 16 | 17 | func didTriggerSettingsEvent() { 18 | router.openSettingsModule() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Routing/Routing/Animator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Animator.swift 3 | // Routing 4 | // 5 | // Created by Nikita Ermolenko on 28/10/2017. 6 | // 7 | 8 | import UIKit 9 | 10 | protocol Animator: UIViewControllerAnimatedTransitioning { 11 | var isPresenting: Bool { get set } 12 | } 13 | -------------------------------------------------------------------------------- /Routing/Routing/Router.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Router.swift 3 | // Routing 4 | // 5 | // Created by Nikita Ermolenko on 29/09/2017. 6 | // 7 | 8 | import UIKit 9 | 10 | protocol Closable: class { 11 | func close() 12 | } 13 | 14 | protocol RouterProtocol: class { 15 | associatedtype V: UIViewController 16 | weak var viewController: V? { get } 17 | 18 | func open(_ viewController: UIViewController, transition: Transition) 19 | } 20 | 21 | class Router: RouterProtocol, Closable where U: UIViewController { 22 | typealias V = U 23 | 24 | weak var viewController: V? 25 | var openTransition: Transition? 26 | 27 | func open(_ viewController: UIViewController, transition: Transition) { 28 | transition.viewController = self.viewController 29 | transition.open(viewController) 30 | } 31 | 32 | func close() { 33 | guard let openTransition = openTransition else { 34 | assertionFailure("You should specify an open transition in order to close a module.") 35 | return 36 | } 37 | guard let viewController = viewController else { 38 | assertionFailure("Nothing to close.") 39 | return 40 | } 41 | openTransition.close(viewController) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Routing/Routing/Routes/AppSettingsRoute.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppSettingsRoute.swift 3 | // Routing 4 | // 5 | // Created by Nikita Ermolenko on 29/09/2017. 6 | // 7 | 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | protocol AppSettingsRoute { 13 | func openAppSettings() 14 | } 15 | 16 | extension AppSettingsRoute { 17 | func openAppSettings() { 18 | UIApplication.shared.open(URL(string:UIApplicationOpenSettingsURLString)!, options: [:], completionHandler: nil) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Routing/Routing/Routes/NoInternetConnectionRoute.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NoInternetConnectionRoute.swift 3 | // Routing 4 | // 5 | // Created by Nikita Ermolenko on 29/09/2017. 6 | // 7 | 8 | import Foundation 9 | import UIKit 10 | 11 | protocol NoInternetConnectionRoute { 12 | func openNoInternetConnectionAlert() 13 | } 14 | 15 | extension NoInternetConnectionRoute where Self: RouterProtocol { 16 | 17 | func openNoInternetConnectionAlert() { 18 | let alertViewController = UIAlertController(title: "Title", message: "No internet connection", preferredStyle: .alert) 19 | viewController?.present(alertViewController, animated: true, completion: nil) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Routing/Routing/Routes/SettingsRoute.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SettingsRoute.swift 3 | // Routing 4 | // 5 | // Created by Nikita Ermolenko on 29/09/2017. 6 | // 7 | 8 | import Foundation 9 | 10 | protocol SettingsRoute { 11 | var settingsTransition: Transition { get } 12 | func openSettingsModule() 13 | } 14 | 15 | extension SettingsRoute where Self: RouterProtocol { 16 | func openSettingsModule() { 17 | let module = SettingsModule() 18 | let transition = settingsTransition // it's a calculated property so I saved it to the variable in order to have one instance 19 | module.router.openTransition = transition 20 | open(module.viewController, transition: transition) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Routing/Routing/Transitions/ModalTransition.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ModalTransition.swift 3 | // Routing 4 | // 5 | // Created by Nikita Ermolenko on 28/10/2017. 6 | // 7 | 8 | import UIKit 9 | 10 | class ModalTransition: NSObject { 11 | 12 | var animator: Animator? 13 | var isAnimated: Bool = true 14 | 15 | var modalTransitionStyle: UIModalTransitionStyle 16 | var modalPresentationStyle: UIModalPresentationStyle 17 | 18 | var completionHandler: (() -> Void)? 19 | 20 | weak var viewController: UIViewController? 21 | 22 | init(animator: Animator? = nil, 23 | isAnimated: Bool = true, 24 | modalTransitionStyle: UIModalTransitionStyle = .coverVertical, 25 | modalPresentationStyle: UIModalPresentationStyle = .fullScreen) { 26 | self.animator = animator 27 | self.isAnimated = isAnimated 28 | self.modalTransitionStyle = modalTransitionStyle 29 | self.modalPresentationStyle = modalPresentationStyle 30 | } 31 | } 32 | 33 | // MARK: - Transition 34 | 35 | extension ModalTransition: Transition { 36 | 37 | func open(_ viewController: UIViewController) { 38 | viewController.transitioningDelegate = self 39 | viewController.modalTransitionStyle = modalTransitionStyle 40 | viewController.modalPresentationStyle = modalPresentationStyle 41 | 42 | self.viewController?.present(viewController, animated: isAnimated, completion: completionHandler) 43 | } 44 | 45 | func close(_ viewController: UIViewController) { 46 | viewController.dismiss(animated: isAnimated, completion: completionHandler) 47 | } 48 | } 49 | 50 | // MARK: - UIViewControllerTransitioningDelegate 51 | 52 | extension ModalTransition: UIViewControllerTransitioningDelegate { 53 | 54 | func animationController(forPresented presented: UIViewController, 55 | presenting: UIViewController, 56 | source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 57 | guard let animator = animator else { 58 | return nil 59 | } 60 | animator.isPresenting = true 61 | return animator 62 | } 63 | 64 | func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 65 | guard let animator = animator else { 66 | return nil 67 | } 68 | animator.isPresenting = false 69 | return animator 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Routing/Routing/Transitions/PushTransition.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PushTransition.swift 3 | // Routing 4 | // 5 | // Created by Nikita Ermolenko on 28/10/2017. 6 | // 7 | 8 | import UIKit 9 | 10 | class PushTransition: NSObject { 11 | 12 | var animator: Animator? 13 | var isAnimated: Bool = true 14 | var completionHandler: (() -> Void)? 15 | 16 | weak var viewController: UIViewController? 17 | 18 | init(animator: Animator? = nil, isAnimated: Bool = true) { 19 | self.animator = animator 20 | self.isAnimated = isAnimated 21 | } 22 | } 23 | 24 | // MARK: - Transition 25 | 26 | extension PushTransition: Transition { 27 | 28 | func open(_ viewController: UIViewController) { 29 | self.viewController?.navigationController?.delegate = self 30 | self.viewController?.navigationController?.pushViewController(viewController, animated: isAnimated) 31 | } 32 | 33 | func close(_ viewController: UIViewController) { 34 | self.viewController?.navigationController?.popViewController(animated: isAnimated) 35 | } 36 | } 37 | 38 | // MARK: - UINavigationControllerDelegate 39 | 40 | extension PushTransition: UINavigationControllerDelegate { 41 | 42 | func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) { 43 | completionHandler?() 44 | } 45 | 46 | func navigationController(_ navigationController: UINavigationController, 47 | animationControllerFor operation: UINavigationControllerOperation, 48 | from fromVC: UIViewController, 49 | to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { 50 | guard let animator = animator else { 51 | return nil 52 | } 53 | if operation == .push { 54 | animator.isPresenting = true 55 | return animator 56 | } 57 | else { 58 | animator.isPresenting = false 59 | return animator 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Routing/Routing/Transitions/Transition.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Transition.swift 3 | // Routing 4 | // 5 | // Created by Nikita Ermolenko on 29/09/2017. 6 | // 7 | 8 | import Foundation 9 | import UIKit 10 | 11 | protocol Transition: class { 12 | weak var viewController: UIViewController? { get set } 13 | 14 | func open(_ viewController: UIViewController) 15 | func close(_ viewController: UIViewController) 16 | } 17 | -------------------------------------------------------------------------------- /Routing/Settings/SettingsModule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SettingsModuleBuilder.swift 3 | // Routing 4 | // 5 | // Created by Nikita Ermolenko on 27/09/2017. 6 | // Copyright © 2017 Rosberry. All rights reserved. 7 | // 8 | 9 | protocol SettingsModuleInput: class { 10 | } 11 | 12 | protocol SettingsModuleOutput: class { 13 | } 14 | 15 | final class SettingsModule { 16 | 17 | var input: SettingsModuleInput { 18 | return viewModel 19 | } 20 | 21 | var output: SettingsModuleOutput? { 22 | set { 23 | viewModel.output = newValue 24 | } 25 | get { 26 | return viewModel.output 27 | } 28 | } 29 | 30 | let router: SettingsRouter 31 | let viewController: SettingsViewController 32 | 33 | private let viewModel: SettingsViewModel 34 | 35 | init() { 36 | let router = SettingsRouter() 37 | let viewModel = SettingsViewModel(router: router) 38 | let viewController = SettingsViewController(viewModel: viewModel) 39 | router.viewController = viewController 40 | 41 | self.router = router 42 | self.viewController = viewController 43 | self.viewModel = viewModel 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Routing/Settings/SettingsRouter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SettingsRouter.swift 3 | // Routing 4 | // 5 | // Created by Nikita Ermolenko on 27/09/2017. 6 | // Copyright © 2017 Rosberry. All rights reserved. 7 | // 8 | 9 | final class SettingsRouter: Router { 10 | 11 | typealias Routes = Closable 12 | } 13 | -------------------------------------------------------------------------------- /Routing/Settings/SettingsViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SettingsViewController.swift 3 | // Routing 4 | // 5 | // Created by Nikita Ermolenko on 27/09/2017. 6 | // Copyright © 2017 Rosberry. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | final class SettingsViewController: UIViewController { 12 | 13 | let viewModel: SettingsViewModel 14 | 15 | private lazy var closeButton: UIButton = { 16 | let button = UIButton() 17 | button.backgroundColor = .red 18 | button.setTitle("Close", for: .normal) 19 | button.addTarget(self, action: #selector(closeButtonPressed), for: .touchUpInside) 20 | return button 21 | }() 22 | 23 | // MARK: - Lifecycle 24 | 25 | init(viewModel: SettingsViewModel) { 26 | self.viewModel = viewModel 27 | super.init(nibName: nil, bundle: nil) 28 | } 29 | 30 | required init?(coder aDecoder: NSCoder) { 31 | fatalError("init(coder:) has not been implemented") 32 | } 33 | 34 | override func viewDidLoad() { 35 | super.viewDidLoad() 36 | view.backgroundColor = .white 37 | view.addSubview(closeButton) 38 | viewModel.didTriggerViewReadyEvent() 39 | } 40 | 41 | override func viewDidLayoutSubviews() { 42 | super.viewDidLayoutSubviews() 43 | 44 | closeButton.frame.size = CGSize(width: 50, height: 50) 45 | closeButton.center = view.center 46 | } 47 | 48 | @objc private func closeButtonPressed(_ sender: UIButton) { 49 | viewModel.closeEvent() 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Routing/Settings/SettingsViewModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SettingsViewModel.swift 3 | // Routing 4 | // 5 | // Created by Nikita Ermolenko on 27/09/2017. 6 | // Copyright © 2017 Rosberry. All rights reserved. 7 | // 8 | 9 | final class SettingsViewModel { 10 | 11 | weak var output: SettingsModuleOutput? 12 | 13 | private let router: SettingsRouter.Routes 14 | 15 | // MARK: - Lifecycle 16 | 17 | init(router: SettingsRouter.Routes) { 18 | self.router = router 19 | } 20 | 21 | func didTriggerViewReadyEvent() { 22 | 23 | } 24 | 25 | func closeEvent() { 26 | router.close() 27 | } 28 | } 29 | 30 | // MARK: - SettingsModuleInput 31 | 32 | extension SettingsViewModel: SettingsModuleInput { 33 | } 34 | -------------------------------------------------------------------------------- /Templates/rsb_swift_service/Code/service.swift.liquid: -------------------------------------------------------------------------------- 1 | {% include 'header' %} 2 | 3 | final class {{ prefix }}{{ module_info.name }}: {{ prefix }}{{ module_info.name }}Protocol { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /Templates/rsb_swift_service/Code/service_protocol.swift.liquid: -------------------------------------------------------------------------------- 1 | {% include 'header' %} 2 | 3 | protocol Has{{ prefix }}{{ module_info.name }} { 4 | var {{ module_info.name }}: {{ prefix }}{{ module_info.name }}Protocol { get } 5 | } 6 | 7 | protocol {{ prefix }}{{ module_info.name }}Protocol { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Templates/rsb_swift_service/rsb_swift_service.rambaspec: -------------------------------------------------------------------------------- 1 | # Template information section 2 | name: "rsb_swift_service" 3 | summary: "Service for DI container." 4 | author: "Evgeny Mikhaylov" 5 | version: "1.0.1" 6 | license: "MIT" 7 | 8 | # The declarations for code files 9 | code_files: 10 | - {name: Protocol.swift, path: Code/service_protocol.swift.liquid} 11 | - {name: .swift, path: Code/service.swift.liquid} 12 | -------------------------------------------------------------------------------- /Templates/rsb_swift_service/snippets/header.liquid: -------------------------------------------------------------------------------- 1 | // 2 | // {{ module_info.file_name }} 3 | // {{ module_info.project_name }} 4 | // 5 | // Created by {{ developer.name }} on {{ date }}. 6 | // Copyright © {{ year }} {{ developer.company }}. All rights reserved. 7 | // -------------------------------------------------------------------------------- /Templates/rsb_swift_viper_vm_di_module/Code/ModuleBuilder.swift.liquid: -------------------------------------------------------------------------------- 1 | {% include 'header' %} 2 | 3 | final class {{ prefix }}{{ module_info.name }}ModuleBuilder { 4 | 5 | static func module(dependencies: {{ prefix }}{{ module_info.name }}Dependencies) -> {{ prefix }}{{ module_info.name }}ViewController { 6 | let router = {{ prefix }}{{ module_info.name }}Router() 7 | let viewModel = {{ prefix }}{{ module_info.name }}ViewModel(router: router) 8 | let viewController = {{ prefix }}{{ module_info.name }}ViewController(viewModel: viewModel) 9 | router.viewController = viewController 10 | return viewController 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Templates/rsb_swift_viper_vm_di_module/Code/Router.swift.liquid: -------------------------------------------------------------------------------- 1 | {% include 'header' %} 2 | 3 | final class {{ prefix }}{{ module_info.name }}Router { 4 | 5 | weak var viewController: {{ prefix }}{{ module_info.name }}ViewController? 6 | } 7 | -------------------------------------------------------------------------------- /Templates/rsb_swift_viper_vm_di_module/Code/ViewController.swift.liquid: -------------------------------------------------------------------------------- 1 | {% include 'header' %} 2 | 3 | import UIKit 4 | 5 | final class {{ prefix }}{{ module_info.name }}ViewController: UIViewController { 6 | 7 | let viewModel: {{ prefix }}{{ module_info.name }}ViewModel 8 | 9 | // MARK: - Lifecycle 10 | 11 | init(viewModel: {{ prefix }}{{ module_info.name }}ViewModel) { 12 | self.viewModel = viewModel 13 | super.init(nibName: nil, bundle: nil) 14 | } 15 | 16 | required init?(coder aDecoder: NSCoder) { 17 | fatalError("init(coder:) has not been implemented") 18 | } 19 | 20 | override func viewDidLoad() { 21 | super.viewDidLoad() 22 | viewModel.didTriggerViewReadyEvent() 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Templates/rsb_swift_viper_vm_di_module/Code/ViewModel.swift.liquid: -------------------------------------------------------------------------------- 1 | {% include 'header' %} 2 | 3 | final class {{ prefix }}{{ module_info.name }}ViewModel { 4 | 5 | private let router: {{ prefix }}{{ module_info.name }}Router 6 | 7 | // MARK: - Lifecycle 8 | 9 | init(router: {{ prefix }}{{ module_info.name }}Router) { 10 | self.router = router 11 | } 12 | 13 | func didTriggerViewReadyEvent() { 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Templates/rsb_swift_viper_vm_di_module/rsb_swift_viper_vm_di_module.rambaspec: -------------------------------------------------------------------------------- 1 | # Template information section 2 | name: "rsb_swift_viper_vm_di_module" 3 | summary: "Base VIPER+VM template for presentation module in Swift project with protocol composition and generics for DI in Interactors." 4 | author: "Artem Novichkov" 5 | version: "1.1.0" 6 | license: "MIT" 7 | 8 | # The declarations for code files 9 | code_files: 10 | - {name: ModuleBuilder.swift, path: Code/ModuleBuilder.swift.liquid} 11 | - {name: ViewController.swift, path: Code/ViewController.swift.liquid} 12 | - {name: ViewModel.swift, path: Code/ViewModel.swift.liquid} 13 | - {name: Router.swift, path: Code/Router.swift.liquid} -------------------------------------------------------------------------------- /Templates/rsb_swift_viper_vm_di_module/snippets/header.liquid: -------------------------------------------------------------------------------- 1 | // 2 | // {{ module_info.file_name }} 3 | // {{ module_info.project_name }} 4 | // 5 | // Created by {{ developer.name }} on {{ date }}. 6 | // Copyright © {{ year }} {{ developer.company }}. All rights reserved. 7 | // --------------------------------------------------------------------------------