├── .gitignore ├── README.md ├── mvvm.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── thomas.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── thomas.xcuserdatad │ └── xcschemes │ ├── mvvm.xcscheme │ └── xcschememanagement.plist └── mvvm ├── AppDelegate.swift ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── CellRepresentable.swift ├── Domain.swift ├── DomainTableViewCell.swift ├── DomainViewModel.swift ├── Info.plist ├── MainViewController.swift ├── Product.swift ├── ProductTableViewCell.swift ├── ProductViewModel.swift └── SearchResultsViewController.swift /.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 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | ## Playgrounds 31 | timeline.xctimeline 32 | playground.xcworkspace 33 | 34 | # Swift Package Manager 35 | # 36 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 37 | # Packages/ 38 | .build/ 39 | 40 | # CocoaPods 41 | # 42 | # We recommend against adding the Pods directory to your .gitignore. However 43 | # you should judge for yourself, the pros and cons are mentioned at: 44 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 45 | # 46 | # Pods/ 47 | 48 | # Carthage 49 | # 50 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 51 | # Carthage/Checkouts 52 | 53 | Carthage/Build 54 | 55 | # fastlane 56 | # 57 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 58 | # screenshots whenever they are needed. 59 | # For more information about the recommended setup visit: 60 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 61 | 62 | fastlane/report.xml 63 | fastlane/Preview.html 64 | fastlane/screenshots 65 | fastlane/test_output 66 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Protocols and MVVM in Swift to avoid repetition demo 2 | This repo contains a demo project for a blogpost for the [ISL Engineering sudo site](https://sudo.isl.co). 3 | 4 | You can find the [blog post here](https://sudo.isl.co/swift-mvvm-protocols/). Tweet at [@thomasdegry](https://twitter.com/thomasdegry) with questions or remarks! 5 | 6 | 👋 7 | -------------------------------------------------------------------------------- /mvvm.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | E92217291E0488E90095E481 /* CellRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = E92217281E0488E90095E481 /* CellRepresentable.swift */; }; 11 | E922172D1E04895E0095E481 /* Domain.swift in Sources */ = {isa = PBXBuildFile; fileRef = E922172C1E04895E0095E481 /* Domain.swift */; }; 12 | E922172F1E0489640095E481 /* Product.swift in Sources */ = {isa = PBXBuildFile; fileRef = E922172E1E0489640095E481 /* Product.swift */; }; 13 | E92217311E0489BE0095E481 /* DomainViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E92217301E0489BE0095E481 /* DomainViewModel.swift */; }; 14 | E92217331E0489CC0095E481 /* ProductViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E92217321E0489CC0095E481 /* ProductViewModel.swift */; }; 15 | E92217361E048AF40095E481 /* DomainTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = E92217351E048AF40095E481 /* DomainTableViewCell.swift */; }; 16 | E92217381E048B000095E481 /* ProductTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = E92217371E048B000095E481 /* ProductTableViewCell.swift */; }; 17 | E922173C1E0490730095E481 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E922173B1E0490730095E481 /* MainViewController.swift */; }; 18 | E9D193391E04568200A66D33 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9D193381E04568200A66D33 /* AppDelegate.swift */; }; 19 | E9D1933B1E04568200A66D33 /* SearchResultsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9D1933A1E04568200A66D33 /* SearchResultsViewController.swift */; }; 20 | E9D1933E1E04568200A66D33 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E9D1933C1E04568200A66D33 /* Main.storyboard */; }; 21 | E9D193401E04568200A66D33 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E9D1933F1E04568200A66D33 /* Assets.xcassets */; }; 22 | E9D193431E04568200A66D33 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E9D193411E04568200A66D33 /* LaunchScreen.storyboard */; }; 23 | /* End PBXBuildFile section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | E92217281E0488E90095E481 /* CellRepresentable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CellRepresentable.swift; sourceTree = ""; }; 27 | E922172C1E04895E0095E481 /* Domain.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Domain.swift; sourceTree = ""; }; 28 | E922172E1E0489640095E481 /* Product.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Product.swift; sourceTree = ""; }; 29 | E92217301E0489BE0095E481 /* DomainViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DomainViewModel.swift; sourceTree = ""; }; 30 | E92217321E0489CC0095E481 /* ProductViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProductViewModel.swift; sourceTree = ""; }; 31 | E92217351E048AF40095E481 /* DomainTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DomainTableViewCell.swift; sourceTree = ""; }; 32 | E92217371E048B000095E481 /* ProductTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProductTableViewCell.swift; sourceTree = ""; }; 33 | E922173B1E0490730095E481 /* MainViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = ""; }; 34 | E9D193351E04568200A66D33 /* mvvm.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = mvvm.app; sourceTree = BUILT_PRODUCTS_DIR; }; 35 | E9D193381E04568200A66D33 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 36 | E9D1933A1E04568200A66D33 /* SearchResultsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResultsViewController.swift; sourceTree = ""; }; 37 | E9D1933D1E04568200A66D33 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 38 | E9D1933F1E04568200A66D33 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 39 | E9D193421E04568200A66D33 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 40 | E9D193441E04568200A66D33 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 41 | /* End PBXFileReference section */ 42 | 43 | /* Begin PBXFrameworksBuildPhase section */ 44 | E9D193321E04568100A66D33 /* Frameworks */ = { 45 | isa = PBXFrameworksBuildPhase; 46 | buildActionMask = 2147483647; 47 | files = ( 48 | ); 49 | runOnlyForDeploymentPostprocessing = 0; 50 | }; 51 | /* End PBXFrameworksBuildPhase section */ 52 | 53 | /* Begin PBXGroup section */ 54 | E922172A1E0489500095E481 /* ViewModels */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | E92217301E0489BE0095E481 /* DomainViewModel.swift */, 58 | E92217321E0489CC0095E481 /* ProductViewModel.swift */, 59 | ); 60 | name = ViewModels; 61 | sourceTree = ""; 62 | }; 63 | E922172B1E0489540095E481 /* Models */ = { 64 | isa = PBXGroup; 65 | children = ( 66 | E922172C1E04895E0095E481 /* Domain.swift */, 67 | E922172E1E0489640095E481 /* Product.swift */, 68 | ); 69 | name = Models; 70 | sourceTree = ""; 71 | }; 72 | E92217341E048ADB0095E481 /* Views */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | E92217351E048AF40095E481 /* DomainTableViewCell.swift */, 76 | E92217371E048B000095E481 /* ProductTableViewCell.swift */, 77 | ); 78 | name = Views; 79 | sourceTree = ""; 80 | }; 81 | E922173D1E0490790095E481 /* View Controllers */ = { 82 | isa = PBXGroup; 83 | children = ( 84 | E922173B1E0490730095E481 /* MainViewController.swift */, 85 | E9D1933A1E04568200A66D33 /* SearchResultsViewController.swift */, 86 | ); 87 | name = "View Controllers"; 88 | sourceTree = ""; 89 | }; 90 | E922173E1E04907F0095E481 /* Protocols */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | E92217281E0488E90095E481 /* CellRepresentable.swift */, 94 | ); 95 | name = Protocols; 96 | sourceTree = ""; 97 | }; 98 | E9D1932C1E04568100A66D33 = { 99 | isa = PBXGroup; 100 | children = ( 101 | E9D193371E04568200A66D33 /* mvvm */, 102 | E9D193361E04568200A66D33 /* Products */, 103 | ); 104 | sourceTree = ""; 105 | }; 106 | E9D193361E04568200A66D33 /* Products */ = { 107 | isa = PBXGroup; 108 | children = ( 109 | E9D193351E04568200A66D33 /* mvvm.app */, 110 | ); 111 | name = Products; 112 | sourceTree = ""; 113 | }; 114 | E9D193371E04568200A66D33 /* mvvm */ = { 115 | isa = PBXGroup; 116 | children = ( 117 | E9D193381E04568200A66D33 /* AppDelegate.swift */, 118 | E922173D1E0490790095E481 /* View Controllers */, 119 | E922173E1E04907F0095E481 /* Protocols */, 120 | E922172B1E0489540095E481 /* Models */, 121 | E922172A1E0489500095E481 /* ViewModels */, 122 | E92217341E048ADB0095E481 /* Views */, 123 | E9D1933C1E04568200A66D33 /* Main.storyboard */, 124 | E9D1933F1E04568200A66D33 /* Assets.xcassets */, 125 | E9D193411E04568200A66D33 /* LaunchScreen.storyboard */, 126 | E9D193441E04568200A66D33 /* Info.plist */, 127 | ); 128 | path = mvvm; 129 | sourceTree = ""; 130 | }; 131 | /* End PBXGroup section */ 132 | 133 | /* Begin PBXNativeTarget section */ 134 | E9D193341E04568100A66D33 /* mvvm */ = { 135 | isa = PBXNativeTarget; 136 | buildConfigurationList = E9D193471E04568200A66D33 /* Build configuration list for PBXNativeTarget "mvvm" */; 137 | buildPhases = ( 138 | E9D193311E04568100A66D33 /* Sources */, 139 | E9D193321E04568100A66D33 /* Frameworks */, 140 | E9D193331E04568100A66D33 /* Resources */, 141 | ); 142 | buildRules = ( 143 | ); 144 | dependencies = ( 145 | ); 146 | name = mvvm; 147 | productName = mvvm; 148 | productReference = E9D193351E04568200A66D33 /* mvvm.app */; 149 | productType = "com.apple.product-type.application"; 150 | }; 151 | /* End PBXNativeTarget section */ 152 | 153 | /* Begin PBXProject section */ 154 | E9D1932D1E04568100A66D33 /* Project object */ = { 155 | isa = PBXProject; 156 | attributes = { 157 | LastSwiftUpdateCheck = 0820; 158 | LastUpgradeCheck = 0820; 159 | ORGANIZATIONNAME = "Thomas Degry"; 160 | TargetAttributes = { 161 | E9D193341E04568100A66D33 = { 162 | CreatedOnToolsVersion = 8.2; 163 | DevelopmentTeam = Z3QGFL558K; 164 | ProvisioningStyle = Automatic; 165 | }; 166 | }; 167 | }; 168 | buildConfigurationList = E9D193301E04568100A66D33 /* Build configuration list for PBXProject "mvvm" */; 169 | compatibilityVersion = "Xcode 3.2"; 170 | developmentRegion = English; 171 | hasScannedForEncodings = 0; 172 | knownRegions = ( 173 | en, 174 | Base, 175 | ); 176 | mainGroup = E9D1932C1E04568100A66D33; 177 | productRefGroup = E9D193361E04568200A66D33 /* Products */; 178 | projectDirPath = ""; 179 | projectRoot = ""; 180 | targets = ( 181 | E9D193341E04568100A66D33 /* mvvm */, 182 | ); 183 | }; 184 | /* End PBXProject section */ 185 | 186 | /* Begin PBXResourcesBuildPhase section */ 187 | E9D193331E04568100A66D33 /* Resources */ = { 188 | isa = PBXResourcesBuildPhase; 189 | buildActionMask = 2147483647; 190 | files = ( 191 | E9D193431E04568200A66D33 /* LaunchScreen.storyboard in Resources */, 192 | E9D193401E04568200A66D33 /* Assets.xcassets in Resources */, 193 | E9D1933E1E04568200A66D33 /* Main.storyboard in Resources */, 194 | ); 195 | runOnlyForDeploymentPostprocessing = 0; 196 | }; 197 | /* End PBXResourcesBuildPhase section */ 198 | 199 | /* Begin PBXSourcesBuildPhase section */ 200 | E9D193311E04568100A66D33 /* Sources */ = { 201 | isa = PBXSourcesBuildPhase; 202 | buildActionMask = 2147483647; 203 | files = ( 204 | E92217331E0489CC0095E481 /* ProductViewModel.swift in Sources */, 205 | E92217311E0489BE0095E481 /* DomainViewModel.swift in Sources */, 206 | E92217381E048B000095E481 /* ProductTableViewCell.swift in Sources */, 207 | E9D1933B1E04568200A66D33 /* SearchResultsViewController.swift in Sources */, 208 | E92217291E0488E90095E481 /* CellRepresentable.swift in Sources */, 209 | E922172F1E0489640095E481 /* Product.swift in Sources */, 210 | E9D193391E04568200A66D33 /* AppDelegate.swift in Sources */, 211 | E922172D1E04895E0095E481 /* Domain.swift in Sources */, 212 | E92217361E048AF40095E481 /* DomainTableViewCell.swift in Sources */, 213 | E922173C1E0490730095E481 /* MainViewController.swift in Sources */, 214 | ); 215 | runOnlyForDeploymentPostprocessing = 0; 216 | }; 217 | /* End PBXSourcesBuildPhase section */ 218 | 219 | /* Begin PBXVariantGroup section */ 220 | E9D1933C1E04568200A66D33 /* Main.storyboard */ = { 221 | isa = PBXVariantGroup; 222 | children = ( 223 | E9D1933D1E04568200A66D33 /* Base */, 224 | ); 225 | name = Main.storyboard; 226 | sourceTree = ""; 227 | }; 228 | E9D193411E04568200A66D33 /* LaunchScreen.storyboard */ = { 229 | isa = PBXVariantGroup; 230 | children = ( 231 | E9D193421E04568200A66D33 /* Base */, 232 | ); 233 | name = LaunchScreen.storyboard; 234 | sourceTree = ""; 235 | }; 236 | /* End PBXVariantGroup section */ 237 | 238 | /* Begin XCBuildConfiguration section */ 239 | E9D193451E04568200A66D33 /* Debug */ = { 240 | isa = XCBuildConfiguration; 241 | buildSettings = { 242 | ALWAYS_SEARCH_USER_PATHS = NO; 243 | CLANG_ANALYZER_NONNULL = YES; 244 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 245 | CLANG_CXX_LIBRARY = "libc++"; 246 | CLANG_ENABLE_MODULES = YES; 247 | CLANG_ENABLE_OBJC_ARC = YES; 248 | CLANG_WARN_BOOL_CONVERSION = YES; 249 | CLANG_WARN_CONSTANT_CONVERSION = YES; 250 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 251 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 252 | CLANG_WARN_EMPTY_BODY = YES; 253 | CLANG_WARN_ENUM_CONVERSION = YES; 254 | CLANG_WARN_INFINITE_RECURSION = YES; 255 | CLANG_WARN_INT_CONVERSION = YES; 256 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 257 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 258 | CLANG_WARN_UNREACHABLE_CODE = YES; 259 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 260 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 261 | COPY_PHASE_STRIP = NO; 262 | DEBUG_INFORMATION_FORMAT = dwarf; 263 | ENABLE_STRICT_OBJC_MSGSEND = YES; 264 | ENABLE_TESTABILITY = YES; 265 | GCC_C_LANGUAGE_STANDARD = gnu99; 266 | GCC_DYNAMIC_NO_PIC = NO; 267 | GCC_NO_COMMON_BLOCKS = YES; 268 | GCC_OPTIMIZATION_LEVEL = 0; 269 | GCC_PREPROCESSOR_DEFINITIONS = ( 270 | "DEBUG=1", 271 | "$(inherited)", 272 | ); 273 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 274 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 275 | GCC_WARN_UNDECLARED_SELECTOR = YES; 276 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 277 | GCC_WARN_UNUSED_FUNCTION = YES; 278 | GCC_WARN_UNUSED_VARIABLE = YES; 279 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 280 | MTL_ENABLE_DEBUG_INFO = YES; 281 | ONLY_ACTIVE_ARCH = YES; 282 | SDKROOT = iphoneos; 283 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 284 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 285 | TARGETED_DEVICE_FAMILY = "1,2"; 286 | }; 287 | name = Debug; 288 | }; 289 | E9D193461E04568200A66D33 /* Release */ = { 290 | isa = XCBuildConfiguration; 291 | buildSettings = { 292 | ALWAYS_SEARCH_USER_PATHS = NO; 293 | CLANG_ANALYZER_NONNULL = YES; 294 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 295 | CLANG_CXX_LIBRARY = "libc++"; 296 | CLANG_ENABLE_MODULES = YES; 297 | CLANG_ENABLE_OBJC_ARC = YES; 298 | CLANG_WARN_BOOL_CONVERSION = YES; 299 | CLANG_WARN_CONSTANT_CONVERSION = YES; 300 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 301 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 302 | CLANG_WARN_EMPTY_BODY = YES; 303 | CLANG_WARN_ENUM_CONVERSION = YES; 304 | CLANG_WARN_INFINITE_RECURSION = YES; 305 | CLANG_WARN_INT_CONVERSION = YES; 306 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 307 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 308 | CLANG_WARN_UNREACHABLE_CODE = YES; 309 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 310 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 311 | COPY_PHASE_STRIP = NO; 312 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 313 | ENABLE_NS_ASSERTIONS = NO; 314 | ENABLE_STRICT_OBJC_MSGSEND = YES; 315 | GCC_C_LANGUAGE_STANDARD = gnu99; 316 | GCC_NO_COMMON_BLOCKS = YES; 317 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 318 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 319 | GCC_WARN_UNDECLARED_SELECTOR = YES; 320 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 321 | GCC_WARN_UNUSED_FUNCTION = YES; 322 | GCC_WARN_UNUSED_VARIABLE = YES; 323 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 324 | MTL_ENABLE_DEBUG_INFO = NO; 325 | SDKROOT = iphoneos; 326 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 327 | TARGETED_DEVICE_FAMILY = "1,2"; 328 | VALIDATE_PRODUCT = YES; 329 | }; 330 | name = Release; 331 | }; 332 | E9D193481E04568200A66D33 /* Debug */ = { 333 | isa = XCBuildConfiguration; 334 | buildSettings = { 335 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 336 | DEVELOPMENT_TEAM = Z3QGFL558K; 337 | INFOPLIST_FILE = mvvm/Info.plist; 338 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 339 | PRODUCT_BUNDLE_IDENTIFIER = co.isl.mvvm; 340 | PRODUCT_NAME = "$(TARGET_NAME)"; 341 | SWIFT_VERSION = 3.0; 342 | }; 343 | name = Debug; 344 | }; 345 | E9D193491E04568200A66D33 /* Release */ = { 346 | isa = XCBuildConfiguration; 347 | buildSettings = { 348 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 349 | DEVELOPMENT_TEAM = Z3QGFL558K; 350 | INFOPLIST_FILE = mvvm/Info.plist; 351 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 352 | PRODUCT_BUNDLE_IDENTIFIER = co.isl.mvvm; 353 | PRODUCT_NAME = "$(TARGET_NAME)"; 354 | SWIFT_VERSION = 3.0; 355 | }; 356 | name = Release; 357 | }; 358 | /* End XCBuildConfiguration section */ 359 | 360 | /* Begin XCConfigurationList section */ 361 | E9D193301E04568100A66D33 /* Build configuration list for PBXProject "mvvm" */ = { 362 | isa = XCConfigurationList; 363 | buildConfigurations = ( 364 | E9D193451E04568200A66D33 /* Debug */, 365 | E9D193461E04568200A66D33 /* Release */, 366 | ); 367 | defaultConfigurationIsVisible = 0; 368 | defaultConfigurationName = Release; 369 | }; 370 | E9D193471E04568200A66D33 /* Build configuration list for PBXNativeTarget "mvvm" */ = { 371 | isa = XCConfigurationList; 372 | buildConfigurations = ( 373 | E9D193481E04568200A66D33 /* Debug */, 374 | E9D193491E04568200A66D33 /* Release */, 375 | ); 376 | defaultConfigurationIsVisible = 0; 377 | defaultConfigurationName = Release; 378 | }; 379 | /* End XCConfigurationList section */ 380 | }; 381 | rootObject = E9D1932D1E04568100A66D33 /* Project object */; 382 | } 383 | -------------------------------------------------------------------------------- /mvvm.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /mvvm.xcodeproj/project.xcworkspace/xcuserdata/thomas.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/istrategylabs/swift-mvvm-protocols/547a0865138daaf627be4fa25e0ba70646903aea/mvvm.xcodeproj/project.xcworkspace/xcuserdata/thomas.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /mvvm.xcodeproj/xcuserdata/thomas.xcuserdatad/xcschemes/mvvm.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /mvvm.xcodeproj/xcuserdata/thomas.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | mvvm.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | E9D193341E04568100A66D33 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /mvvm/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // mvvm 4 | // 5 | // Created by Thomas Degry on 12/16/16. 6 | // Copyright © 2016 Thomas Degry. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // 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. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // 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. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // 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. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // 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. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /mvvm/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /mvvm/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 | 27 | 28 | -------------------------------------------------------------------------------- /mvvm/Base.lproj/Main.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 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 49 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 73 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /mvvm/CellRepresentable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CellRepresentable.swift 3 | // mvvm 4 | // 5 | // Created by Thomas Degry on 12/16/16. 6 | // Copyright © 2016 Thomas Degry. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | protocol CellRepresentable { 12 | var rowHeight: CGFloat { get } 13 | func cellInstance(_ tableView: UITableView, indexPath: IndexPath) -> UITableViewCell 14 | } 15 | -------------------------------------------------------------------------------- /mvvm/Domain.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Domain.swift 3 | // mvvm 4 | // 5 | // Created by Thomas Degry on 12/16/16. 6 | // Copyright © 2016 Thomas Degry. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | enum DomainStatus { 12 | case Available 13 | case Taken 14 | case Other 15 | } 16 | 17 | struct Domain { 18 | var domainName: String 19 | var domainStatus: DomainStatus 20 | } 21 | -------------------------------------------------------------------------------- /mvvm/DomainTableViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DomainTableViewCell.swift 3 | // mvvm 4 | // 5 | // Created by Thomas Degry on 12/16/16. 6 | // Copyright © 2016 Thomas Degry. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class DomainTableViewCell: UITableViewCell { 12 | func setup(vm: DomainViewModel) { 13 | self.textLabel?.text = vm.domain.domainName 14 | self.detailTextLabel?.text = vm.status 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /mvvm/DomainViewModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DomainViewModel.swift 3 | // mvvm 4 | // 5 | // Created by Thomas Degry on 12/16/16. 6 | // Copyright © 2016 Thomas Degry. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class DomainViewModel: CellRepresentable { 12 | var domain: Domain 13 | var rowHeight: CGFloat = 60 14 | 15 | var status: String { 16 | switch domain.domainStatus { 17 | case .Available: 18 | return "Available" 19 | case .Taken: 20 | return "Taken" 21 | case .Other: 22 | return "Other" 23 | } 24 | } 25 | 26 | init(domain: Domain) { 27 | self.domain = domain 28 | } 29 | 30 | func cellInstance(_ tableView: UITableView, indexPath: IndexPath) -> UITableViewCell { 31 | // Dequeue a cell 32 | let cell = tableView.dequeueReusableCell(withIdentifier: "DomainCell", for: indexPath) as! DomainTableViewCell 33 | 34 | // Pass ourselves (the view model) to setup the cell 35 | cell.setup(vm: self) 36 | 37 | // Return the cell 38 | return cell 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /mvvm/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 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 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /mvvm/MainViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MainViewController.swift 3 | // mvvm 4 | // 5 | // Created by Thomas Degry on 12/16/16. 6 | // Copyright © 2016 Thomas Degry. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class MainViewController: UITabBarController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | 16 | // Add VC's 17 | let storyboard = UIStoryboard(name: "Main", bundle: nil) 18 | 19 | // Generate the ProductVC and some products 20 | let productsVC = storyboard.instantiateViewController(withIdentifier: "ResultsVC") as! SearchresultsViewController 21 | productsVC.title = "Products" 22 | productsVC.data = [ 23 | ProductViewModel(product: Product(name: "Preflight Airport Parking", rating: 2.0, price: nil)), 24 | ProductViewModel(product: Product(name: "Adobe Experience Manager", rating: 4.0, price: nil)), 25 | ProductViewModel(product: Product(name: "RedBull Flugtag Pre-Flight", rating: 3.0, price: nil)), 26 | ProductViewModel(product: Product(name: "PreFlight", rating: 2.0, price: 4.99)), 27 | ProductViewModel(product: Product(name: "PAW Patrol pups Take Flight", rating: 2.0, price: 2.99)) 28 | ] 29 | 30 | // Generate the DomainsVC and some domains 31 | let domainsVC = storyboard.instantiateViewController(withIdentifier: "ResultsVC") as! SearchresultsViewController 32 | domainsVC.title = "Domains" 33 | domainsVC.data = [ 34 | DomainViewModel(domain: Domain(domainName: "facebook.com", domainStatus: .Taken)), 35 | DomainViewModel(domain: Domain(domainName: "facebook.org", domainStatus: .Available)), 36 | DomainViewModel(domain: Domain(domainName: "facebook.net", domainStatus: .Available)), 37 | DomainViewModel(domain: Domain(domainName: "facebook.edu", domainStatus: .Other)), 38 | ] 39 | 40 | // Set the created VCs as the view controllers for our tabbar 41 | self.setViewControllers([productsVC, domainsVC], animated: false) 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /mvvm/Product.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Product.swift 3 | // mvvm 4 | // 5 | // Created by Thomas Degry on 12/16/16. 6 | // Copyright © 2016 Thomas Degry. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | struct Product { 12 | var name: String 13 | var rating: Double 14 | var price: Double? 15 | } 16 | -------------------------------------------------------------------------------- /mvvm/ProductTableViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ProductTableViewCell.swift 3 | // mvvm 4 | // 5 | // Created by Thomas Degry on 12/16/16. 6 | // Copyright © 2016 Thomas Degry. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ProductTableViewCell: UITableViewCell { 12 | func setup(vm: ProductViewModel) { 13 | self.textLabel?.text = vm.product.name 14 | self.detailTextLabel?.text = vm.price 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /mvvm/ProductViewModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ProductViewModel.swift 3 | // mvvm 4 | // 5 | // Created by Thomas Degry on 12/16/16. 6 | // Copyright © 2016 Thomas Degry. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ProductViewModel: CellRepresentable { 12 | var product: Product 13 | var rowHeight: CGFloat = 80 14 | 15 | var price: String { 16 | guard let price = product.price else { 17 | return "free" 18 | } 19 | 20 | return "$\(price)" 21 | } 22 | 23 | init(product: Product) { 24 | self.product = product 25 | } 26 | 27 | func cellInstance(_ tableView: UITableView, indexPath: IndexPath) -> UITableViewCell { 28 | // Dequeue a cell 29 | let cell = tableView.dequeueReusableCell(withIdentifier: "ProductCell", for: indexPath) as! ProductTableViewCell 30 | 31 | // Pass ourselves (the view model) to setup the cell 32 | cell.setup(vm: self) 33 | 34 | // Return the cell 35 | return cell 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /mvvm/SearchResultsViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // mvvm 4 | // 5 | // Created by Thomas Degry on 12/16/16. 6 | // Copyright © 2016 Thomas Degry. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SearchresultsViewController: UIViewController { 12 | // Outlets 13 | @IBOutlet weak var titleLabel: UILabel! 14 | @IBOutlet weak var tableView: UITableView! 15 | 16 | // Init an empty cell representable array 17 | var data = [CellRepresentable]() 18 | 19 | override func viewDidLoad() { 20 | super.viewDidLoad() 21 | 22 | // Update the title label 23 | if let title = title { 24 | titleLabel.text = "\(title) Results" 25 | } 26 | } 27 | } 28 | 29 | extension SearchresultsViewController: UITableViewDataSource { 30 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 31 | return data.count 32 | } 33 | 34 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 35 | return data[indexPath.row].cellInstance(tableView, indexPath: indexPath) 36 | } 37 | } 38 | 39 | extension SearchresultsViewController: UITableViewDelegate { 40 | func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 41 | return data[indexPath.row].rowHeight 42 | } 43 | } 44 | --------------------------------------------------------------------------------