├── .gitignore ├── LICENSE ├── README.md ├── TodoMVC.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcuserdata │ └── ryanashcraft.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── TodoMVC ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ └── LaunchScreen.storyboard ├── ContentView.swift ├── Info.plist ├── ItemView.swift ├── Preview Content │ └── Preview Assets.xcassets │ │ └── Contents.json ├── SceneDelegate.swift └── TodoViewModel.swift └── screenshot.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## Xcode Patch 26 | *.xcodeproj/* 27 | !*.xcodeproj/project.pbxproj 28 | !*.xcodeproj/xcshareddata/ 29 | !*.xcworkspace/contents.xcworkspacedata 30 | /*.gcno 31 | 32 | ## macOS 33 | .DS_Store 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Ryan Ashcraft 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 | # SwiftUI-TodoMVC 2 | 3 | [TodoMVC](http://todomvc.com/) implemented in [SwiftUI](https://developer.apple.com/xcode/swiftui/). 4 | 5 | ![Screenshot](./screenshot.png) 6 | -------------------------------------------------------------------------------- /TodoMVC.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | ED18027D22D5164C00F2DA71 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED18027C22D5164C00F2DA71 /* AppDelegate.swift */; }; 11 | ED18027F22D5164C00F2DA71 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED18027E22D5164C00F2DA71 /* SceneDelegate.swift */; }; 12 | ED18028122D5164C00F2DA71 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED18028022D5164C00F2DA71 /* ContentView.swift */; }; 13 | ED18028322D5164C00F2DA71 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = ED18028222D5164C00F2DA71 /* Assets.xcassets */; }; 14 | ED18028622D5164C00F2DA71 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = ED18028522D5164C00F2DA71 /* Preview Assets.xcassets */; }; 15 | ED18028922D5164C00F2DA71 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = ED18028722D5164C00F2DA71 /* LaunchScreen.storyboard */; }; 16 | ED18029122D5168900F2DA71 /* TodoViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED18029022D5168900F2DA71 /* TodoViewModel.swift */; }; 17 | ED18029322D516AA00F2DA71 /* ItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED18029222D516AA00F2DA71 /* ItemView.swift */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | ED18027922D5164C00F2DA71 /* TodoMVC.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TodoMVC.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | ED18027C22D5164C00F2DA71 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 23 | ED18027E22D5164C00F2DA71 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 24 | ED18028022D5164C00F2DA71 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 25 | ED18028222D5164C00F2DA71 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 26 | ED18028522D5164C00F2DA71 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 27 | ED18028822D5164C00F2DA71 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 28 | ED18028A22D5164C00F2DA71 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 29 | ED18029022D5168900F2DA71 /* TodoViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodoViewModel.swift; sourceTree = ""; }; 30 | ED18029222D516AA00F2DA71 /* ItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemView.swift; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | ED18027622D5164C00F2DA71 /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | ); 39 | runOnlyForDeploymentPostprocessing = 0; 40 | }; 41 | /* End PBXFrameworksBuildPhase section */ 42 | 43 | /* Begin PBXGroup section */ 44 | ED18027022D5164C00F2DA71 = { 45 | isa = PBXGroup; 46 | children = ( 47 | ED18027B22D5164C00F2DA71 /* TodoMVC */, 48 | ED18027A22D5164C00F2DA71 /* Products */, 49 | ); 50 | sourceTree = ""; 51 | }; 52 | ED18027A22D5164C00F2DA71 /* Products */ = { 53 | isa = PBXGroup; 54 | children = ( 55 | ED18027922D5164C00F2DA71 /* TodoMVC.app */, 56 | ); 57 | name = Products; 58 | sourceTree = ""; 59 | }; 60 | ED18027B22D5164C00F2DA71 /* TodoMVC */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | ED18027C22D5164C00F2DA71 /* AppDelegate.swift */, 64 | ED18027E22D5164C00F2DA71 /* SceneDelegate.swift */, 65 | ED18028022D5164C00F2DA71 /* ContentView.swift */, 66 | ED18029222D516AA00F2DA71 /* ItemView.swift */, 67 | ED18029022D5168900F2DA71 /* TodoViewModel.swift */, 68 | ED18028222D5164C00F2DA71 /* Assets.xcassets */, 69 | ED18028722D5164C00F2DA71 /* LaunchScreen.storyboard */, 70 | ED18028A22D5164C00F2DA71 /* Info.plist */, 71 | ED18028422D5164C00F2DA71 /* Preview Content */, 72 | ); 73 | path = TodoMVC; 74 | sourceTree = ""; 75 | }; 76 | ED18028422D5164C00F2DA71 /* Preview Content */ = { 77 | isa = PBXGroup; 78 | children = ( 79 | ED18028522D5164C00F2DA71 /* Preview Assets.xcassets */, 80 | ); 81 | path = "Preview Content"; 82 | sourceTree = ""; 83 | }; 84 | /* End PBXGroup section */ 85 | 86 | /* Begin PBXNativeTarget section */ 87 | ED18027822D5164C00F2DA71 /* TodoMVC */ = { 88 | isa = PBXNativeTarget; 89 | buildConfigurationList = ED18028D22D5164C00F2DA71 /* Build configuration list for PBXNativeTarget "TodoMVC" */; 90 | buildPhases = ( 91 | ED18027522D5164C00F2DA71 /* Sources */, 92 | ED18027622D5164C00F2DA71 /* Frameworks */, 93 | ED18027722D5164C00F2DA71 /* Resources */, 94 | ); 95 | buildRules = ( 96 | ); 97 | dependencies = ( 98 | ); 99 | name = TodoMVC; 100 | productName = TodoMVC; 101 | productReference = ED18027922D5164C00F2DA71 /* TodoMVC.app */; 102 | productType = "com.apple.product-type.application"; 103 | }; 104 | /* End PBXNativeTarget section */ 105 | 106 | /* Begin PBXProject section */ 107 | ED18027122D5164C00F2DA71 /* Project object */ = { 108 | isa = PBXProject; 109 | attributes = { 110 | LastSwiftUpdateCheck = 1100; 111 | LastUpgradeCheck = 1100; 112 | ORGANIZATIONNAME = "Ryan Ashcraft"; 113 | TargetAttributes = { 114 | ED18027822D5164C00F2DA71 = { 115 | CreatedOnToolsVersion = 11.0; 116 | }; 117 | }; 118 | }; 119 | buildConfigurationList = ED18027422D5164C00F2DA71 /* Build configuration list for PBXProject "TodoMVC" */; 120 | compatibilityVersion = "Xcode 9.3"; 121 | developmentRegion = en; 122 | hasScannedForEncodings = 0; 123 | knownRegions = ( 124 | en, 125 | Base, 126 | ); 127 | mainGroup = ED18027022D5164C00F2DA71; 128 | productRefGroup = ED18027A22D5164C00F2DA71 /* Products */; 129 | projectDirPath = ""; 130 | projectRoot = ""; 131 | targets = ( 132 | ED18027822D5164C00F2DA71 /* TodoMVC */, 133 | ); 134 | }; 135 | /* End PBXProject section */ 136 | 137 | /* Begin PBXResourcesBuildPhase section */ 138 | ED18027722D5164C00F2DA71 /* Resources */ = { 139 | isa = PBXResourcesBuildPhase; 140 | buildActionMask = 2147483647; 141 | files = ( 142 | ED18028922D5164C00F2DA71 /* LaunchScreen.storyboard in Resources */, 143 | ED18028622D5164C00F2DA71 /* Preview Assets.xcassets in Resources */, 144 | ED18028322D5164C00F2DA71 /* Assets.xcassets in Resources */, 145 | ); 146 | runOnlyForDeploymentPostprocessing = 0; 147 | }; 148 | /* End PBXResourcesBuildPhase section */ 149 | 150 | /* Begin PBXSourcesBuildPhase section */ 151 | ED18027522D5164C00F2DA71 /* Sources */ = { 152 | isa = PBXSourcesBuildPhase; 153 | buildActionMask = 2147483647; 154 | files = ( 155 | ED18027D22D5164C00F2DA71 /* AppDelegate.swift in Sources */, 156 | ED18027F22D5164C00F2DA71 /* SceneDelegate.swift in Sources */, 157 | ED18029122D5168900F2DA71 /* TodoViewModel.swift in Sources */, 158 | ED18029322D516AA00F2DA71 /* ItemView.swift in Sources */, 159 | ED18028122D5164C00F2DA71 /* ContentView.swift in Sources */, 160 | ); 161 | runOnlyForDeploymentPostprocessing = 0; 162 | }; 163 | /* End PBXSourcesBuildPhase section */ 164 | 165 | /* Begin PBXVariantGroup section */ 166 | ED18028722D5164C00F2DA71 /* LaunchScreen.storyboard */ = { 167 | isa = PBXVariantGroup; 168 | children = ( 169 | ED18028822D5164C00F2DA71 /* Base */, 170 | ); 171 | name = LaunchScreen.storyboard; 172 | sourceTree = ""; 173 | }; 174 | /* End PBXVariantGroup section */ 175 | 176 | /* Begin XCBuildConfiguration section */ 177 | ED18028B22D5164C00F2DA71 /* Debug */ = { 178 | isa = XCBuildConfiguration; 179 | buildSettings = { 180 | ALWAYS_SEARCH_USER_PATHS = NO; 181 | CLANG_ANALYZER_NONNULL = YES; 182 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 183 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 184 | CLANG_CXX_LIBRARY = "libc++"; 185 | CLANG_ENABLE_MODULES = YES; 186 | CLANG_ENABLE_OBJC_ARC = YES; 187 | CLANG_ENABLE_OBJC_WEAK = YES; 188 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 189 | CLANG_WARN_BOOL_CONVERSION = YES; 190 | CLANG_WARN_COMMA = YES; 191 | CLANG_WARN_CONSTANT_CONVERSION = YES; 192 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 193 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 194 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 195 | CLANG_WARN_EMPTY_BODY = YES; 196 | CLANG_WARN_ENUM_CONVERSION = YES; 197 | CLANG_WARN_INFINITE_RECURSION = YES; 198 | CLANG_WARN_INT_CONVERSION = YES; 199 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 200 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 201 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 202 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 203 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 204 | CLANG_WARN_STRICT_PROTOTYPES = YES; 205 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 206 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 207 | CLANG_WARN_UNREACHABLE_CODE = YES; 208 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 209 | COPY_PHASE_STRIP = NO; 210 | DEBUG_INFORMATION_FORMAT = dwarf; 211 | ENABLE_STRICT_OBJC_MSGSEND = YES; 212 | ENABLE_TESTABILITY = YES; 213 | GCC_C_LANGUAGE_STANDARD = gnu11; 214 | GCC_DYNAMIC_NO_PIC = NO; 215 | GCC_NO_COMMON_BLOCKS = YES; 216 | GCC_OPTIMIZATION_LEVEL = 0; 217 | GCC_PREPROCESSOR_DEFINITIONS = ( 218 | "DEBUG=1", 219 | "$(inherited)", 220 | ); 221 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 222 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 223 | GCC_WARN_UNDECLARED_SELECTOR = YES; 224 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 225 | GCC_WARN_UNUSED_FUNCTION = YES; 226 | GCC_WARN_UNUSED_VARIABLE = YES; 227 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 228 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 229 | MTL_FAST_MATH = YES; 230 | ONLY_ACTIVE_ARCH = YES; 231 | SDKROOT = iphoneos; 232 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 233 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 234 | }; 235 | name = Debug; 236 | }; 237 | ED18028C22D5164C00F2DA71 /* Release */ = { 238 | isa = XCBuildConfiguration; 239 | buildSettings = { 240 | ALWAYS_SEARCH_USER_PATHS = NO; 241 | CLANG_ANALYZER_NONNULL = YES; 242 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 243 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 244 | CLANG_CXX_LIBRARY = "libc++"; 245 | CLANG_ENABLE_MODULES = YES; 246 | CLANG_ENABLE_OBJC_ARC = YES; 247 | CLANG_ENABLE_OBJC_WEAK = YES; 248 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 249 | CLANG_WARN_BOOL_CONVERSION = YES; 250 | CLANG_WARN_COMMA = YES; 251 | CLANG_WARN_CONSTANT_CONVERSION = YES; 252 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 253 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 254 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 255 | CLANG_WARN_EMPTY_BODY = YES; 256 | CLANG_WARN_ENUM_CONVERSION = YES; 257 | CLANG_WARN_INFINITE_RECURSION = YES; 258 | CLANG_WARN_INT_CONVERSION = YES; 259 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 260 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 261 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 262 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 263 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 264 | CLANG_WARN_STRICT_PROTOTYPES = YES; 265 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 266 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 267 | CLANG_WARN_UNREACHABLE_CODE = YES; 268 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 269 | COPY_PHASE_STRIP = NO; 270 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 271 | ENABLE_NS_ASSERTIONS = NO; 272 | ENABLE_STRICT_OBJC_MSGSEND = YES; 273 | GCC_C_LANGUAGE_STANDARD = gnu11; 274 | GCC_NO_COMMON_BLOCKS = YES; 275 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 276 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 277 | GCC_WARN_UNDECLARED_SELECTOR = YES; 278 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 279 | GCC_WARN_UNUSED_FUNCTION = YES; 280 | GCC_WARN_UNUSED_VARIABLE = YES; 281 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 282 | MTL_ENABLE_DEBUG_INFO = NO; 283 | MTL_FAST_MATH = YES; 284 | SDKROOT = iphoneos; 285 | SWIFT_COMPILATION_MODE = wholemodule; 286 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 287 | VALIDATE_PRODUCT = YES; 288 | }; 289 | name = Release; 290 | }; 291 | ED18028E22D5164C00F2DA71 /* Debug */ = { 292 | isa = XCBuildConfiguration; 293 | buildSettings = { 294 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 295 | CODE_SIGN_STYLE = Automatic; 296 | DEVELOPMENT_ASSET_PATHS = "TodoMVC/Preview\\ Content"; 297 | DEVELOPMENT_TEAM = V5TNS56NL8; 298 | ENABLE_PREVIEWS = YES; 299 | INFOPLIST_FILE = TodoMVC/Info.plist; 300 | LD_RUNPATH_SEARCH_PATHS = ( 301 | "$(inherited)", 302 | "@executable_path/Frameworks", 303 | ); 304 | PRODUCT_BUNDLE_IDENTIFIER = me.ryanashcraft.TodoMVC; 305 | PRODUCT_NAME = "$(TARGET_NAME)"; 306 | SWIFT_VERSION = 5.0; 307 | TARGETED_DEVICE_FAMILY = "1,2"; 308 | }; 309 | name = Debug; 310 | }; 311 | ED18028F22D5164C00F2DA71 /* Release */ = { 312 | isa = XCBuildConfiguration; 313 | buildSettings = { 314 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 315 | CODE_SIGN_STYLE = Automatic; 316 | DEVELOPMENT_ASSET_PATHS = "TodoMVC/Preview\\ Content"; 317 | DEVELOPMENT_TEAM = V5TNS56NL8; 318 | ENABLE_PREVIEWS = YES; 319 | INFOPLIST_FILE = TodoMVC/Info.plist; 320 | LD_RUNPATH_SEARCH_PATHS = ( 321 | "$(inherited)", 322 | "@executable_path/Frameworks", 323 | ); 324 | PRODUCT_BUNDLE_IDENTIFIER = me.ryanashcraft.TodoMVC; 325 | PRODUCT_NAME = "$(TARGET_NAME)"; 326 | SWIFT_VERSION = 5.0; 327 | TARGETED_DEVICE_FAMILY = "1,2"; 328 | }; 329 | name = Release; 330 | }; 331 | /* End XCBuildConfiguration section */ 332 | 333 | /* Begin XCConfigurationList section */ 334 | ED18027422D5164C00F2DA71 /* Build configuration list for PBXProject "TodoMVC" */ = { 335 | isa = XCConfigurationList; 336 | buildConfigurations = ( 337 | ED18028B22D5164C00F2DA71 /* Debug */, 338 | ED18028C22D5164C00F2DA71 /* Release */, 339 | ); 340 | defaultConfigurationIsVisible = 0; 341 | defaultConfigurationName = Release; 342 | }; 343 | ED18028D22D5164C00F2DA71 /* Build configuration list for PBXNativeTarget "TodoMVC" */ = { 344 | isa = XCConfigurationList; 345 | buildConfigurations = ( 346 | ED18028E22D5164C00F2DA71 /* Debug */, 347 | ED18028F22D5164C00F2DA71 /* Release */, 348 | ); 349 | defaultConfigurationIsVisible = 0; 350 | defaultConfigurationName = Release; 351 | }; 352 | /* End XCConfigurationList section */ 353 | }; 354 | rootObject = ED18027122D5164C00F2DA71 /* Project object */; 355 | } 356 | -------------------------------------------------------------------------------- /TodoMVC.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TodoMVC.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /TodoMVC.xcodeproj/xcuserdata/ryanashcraft.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | TodoMVC.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /TodoMVC/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // TodoMVC 4 | // 5 | // Created by Ryan Ashcraft on 7/9/19. 6 | // Copyright © 2019 Ryan Ashcraft. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 14 | // Override point for customization after application launch. 15 | return true 16 | } 17 | 18 | // MARK: UISceneSession Lifecycle 19 | 20 | func application(_: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options _: UIScene.ConnectionOptions) -> UISceneConfiguration { 21 | // Called when a new scene session is being created. 22 | // Use this method to select a configuration to create the new scene with. 23 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 24 | } 25 | 26 | func application(_: UIApplication, didDiscardSceneSessions _: Set) { 27 | // Called when the user discards a scene session. 28 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 29 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /TodoMVC/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 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /TodoMVC/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /TodoMVC/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 | -------------------------------------------------------------------------------- /TodoMVC/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // TodoMVC 4 | // 5 | // Created by Ryan Ashcraft on 7/9/19. 6 | // Copyright © 2019 Ryan Ashcraft. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | struct ContentView: View { 12 | private enum ItemStatusFilter { 13 | case all 14 | case active 15 | case completed 16 | } 17 | 18 | @ObservedObject private var viewModel = TodoViewModel() 19 | @State private var newTitle = "" 20 | @State private var view: ItemStatusFilter = .all 21 | 22 | func shouldShowItem(item: TodoItem) -> Bool { 23 | switch view { 24 | case .all: return true 25 | case .active: return !item.isCompleted 26 | case .completed: return item.isCompleted 27 | } 28 | } 29 | 30 | var title: some View { 31 | Text("todos") 32 | .foregroundColor(Color(hue: 0, saturation: 0.57, brightness: 0.43, opacity: 0.15)) 33 | .font(Font.system(size: 80).weight(.thin)) 34 | .padding(.top) 35 | } 36 | 37 | var createItemBar: some View { 38 | HStack { 39 | if !self.viewModel.items.isEmpty { 40 | Button(action: { self.viewModel.toggleAllCompleted() }, label: { 41 | Image(systemName: "chevron.down") 42 | .foregroundColor(self.viewModel.areAllCompleted ? Color.gray : Color.gray.opacity(0.5)) 43 | .frame(width: 20, height: 20) 44 | .padding() 45 | }) 46 | } 47 | 48 | TextField( 49 | "What needs to be done?", 50 | text: self.$newTitle, 51 | onEditingChanged: { _ in }, 52 | onCommit: { 53 | if !self.newTitle.isEmpty { 54 | self.viewModel.createTodo(title: self.newTitle) 55 | self.newTitle = "" 56 | } 57 | } 58 | ) 59 | .padding(self.viewModel.items.isEmpty ? .horizontal : .trailing) 60 | .font(self.newTitle.isEmpty ? Font.body.italic() : Font.body) 61 | .frame(height: 60) 62 | } 63 | } 64 | 65 | var itemDivider: some View { 66 | Rectangle() 67 | .fill(Color(white: 0.9)) 68 | .frame(height: 0.5) 69 | } 70 | 71 | var filterControls: some View { 72 | VStack(alignment: .center, spacing: 16) { 73 | Picker(selection: self.$view, label: Text("Status")) { 74 | Text("All").tag(ItemStatusFilter.all) 75 | Text("Active").tag(ItemStatusFilter.active) 76 | Text("Completed").tag(ItemStatusFilter.completed) 77 | } 78 | .pickerStyle(SegmentedPickerStyle()) 79 | 80 | HStack { 81 | Text("\(self.viewModel.incompleteCount) item\(self.viewModel.incompleteCount == 1 ? "" : "s") left\(self.viewModel.completeCount > 0 ? "." : "")") 82 | .foregroundColor(Color.gray) 83 | if self.viewModel.completeCount > 0 { 84 | Button("Clear completed.", action: { 85 | self.viewModel.clearCompleted() 86 | }) 87 | } 88 | } 89 | .font(Font.caption) 90 | .animation(nil) 91 | } 92 | .padding(.horizontal) 93 | } 94 | 95 | var body: some View { 96 | ScrollView { 97 | VStack(alignment: .center, spacing: 0) { 98 | title 99 | 100 | VStack(alignment: .leading, spacing: 0) { 101 | createItemBar 102 | 103 | VStack(alignment: .leading, spacing: 0) { 104 | ForEach(self.viewModel.items.filter(self.shouldShowItem)) { 105 | self.itemDivider 106 | Item(viewModel: self.viewModel, item: $0) 107 | } 108 | } 109 | } 110 | .background( 111 | Color.white 112 | .shadow( 113 | color: Color(hue: 0, saturation: 0, brightness: 0, opacity: 0.1), 114 | radius: 4, 115 | x: 0, 116 | y: 2 117 | ) 118 | ) 119 | .padding() 120 | 121 | if !self.viewModel.items.isEmpty { 122 | filterControls 123 | } 124 | } 125 | .frame(maxWidth: 550, alignment: .center) 126 | } 127 | .frame(maxWidth: .infinity) 128 | .background( 129 | Color(white: 0.96) 130 | .edgesIgnoringSafeArea(.all) 131 | ) 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /TodoMVC/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 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UILaunchStoryboardName 33 | LaunchScreen 34 | UISceneConfigurationName 35 | Default Configuration 36 | UISceneDelegateClassName 37 | $(PRODUCT_MODULE_NAME).SceneDelegate 38 | 39 | 40 | 41 | 42 | UILaunchStoryboardName 43 | LaunchScreen 44 | UIRequiredDeviceCapabilities 45 | 46 | armv7 47 | 48 | UISupportedInterfaceOrientations 49 | 50 | UIInterfaceOrientationPortrait 51 | UIInterfaceOrientationLandscapeLeft 52 | UIInterfaceOrientationLandscapeRight 53 | 54 | UISupportedInterfaceOrientations~ipad 55 | 56 | UIInterfaceOrientationPortrait 57 | UIInterfaceOrientationPortraitUpsideDown 58 | UIInterfaceOrientationLandscapeLeft 59 | UIInterfaceOrientationLandscapeRight 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /TodoMVC/ItemView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ItemView.swift 3 | // TodoMVC 4 | // 5 | // Created by Ryan Ashcraft on 7/9/19. 6 | // Copyright © 2019 Ryan Ashcraft. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | struct CompleteButton: View { 12 | let isCompleted: Bool 13 | let action: () -> Void 14 | 15 | var body: some View { 16 | Button(action: self.action) { 17 | ZStack { 18 | Circle() 19 | .stroke(isCompleted ? Color.green : Color.gray, lineWidth: 1.5) 20 | .frame(width: 20, height: 20) 21 | 22 | if isCompleted { 23 | Circle() 24 | .fill(Color.green) 25 | .frame(width: 12.5, height: 12.5) 26 | } 27 | } 28 | .padding() 29 | } 30 | } 31 | } 32 | 33 | struct Item: View { 34 | @ObservedObject var viewModel: TodoViewModel 35 | var item: TodoItem 36 | 37 | var titleBinding: Binding { 38 | Binding( 39 | get: { 40 | self.item.title 41 | }, 42 | set: { 43 | self.viewModel.setTitle(itemId: self.item.id, title: $0) 44 | } 45 | ) 46 | } 47 | 48 | var body: some View { 49 | HStack(alignment: .center) { 50 | CompleteButton( 51 | isCompleted: self.item.isCompleted, 52 | action: { 53 | self.viewModel.setIsCompleted(itemId: self.item.id, isCompleted: !self.item.isCompleted) 54 | } 55 | ) 56 | 57 | TextField("Title", text: titleBinding) 58 | .padding(.vertical) 59 | .background(Color.white) 60 | .foregroundColor(self.item.isCompleted ? Color.gray : Color.black) 61 | .layoutPriority(1) 62 | 63 | Spacer() 64 | 65 | Button(action: { self.viewModel.removeItem(itemId: self.item.id) }) { 66 | Image(systemName: "trash") 67 | .padding() 68 | } 69 | } 70 | .frame(height: 60) 71 | .background(Color.white) 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /TodoMVC/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /TodoMVC/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // TodoMVC 4 | // 5 | // Created by Ryan Ashcraft on 7/9/19. 6 | // Copyright © 2019 Ryan Ashcraft. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | import UIKit 11 | 12 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 13 | var window: UIWindow? 14 | 15 | func scene(_ scene: UIScene, willConnectTo _: UISceneSession, options _: UIScene.ConnectionOptions) { 16 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 17 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 18 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 19 | 20 | // Use a UIHostingController as window root view controller 21 | if let windowScene = scene as? UIWindowScene { 22 | let window = UIWindow(windowScene: windowScene) 23 | window.rootViewController = UIHostingController(rootView: ContentView()) 24 | self.window = window 25 | window.makeKeyAndVisible() 26 | } 27 | } 28 | 29 | func sceneDidDisconnect(_: UIScene) { 30 | // Called as the scene is being released by the system. 31 | // This occurs shortly after the scene enters the background, or when its session is discarded. 32 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 33 | // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). 34 | } 35 | 36 | func sceneDidBecomeActive(_: UIScene) { 37 | // Called when the scene has moved from an inactive state to an active state. 38 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 39 | } 40 | 41 | func sceneWillResignActive(_: UIScene) { 42 | // Called when the scene will move from an active state to an inactive state. 43 | // This may occur due to temporary interruptions (ex. an incoming phone call). 44 | } 45 | 46 | func sceneWillEnterForeground(_: UIScene) { 47 | // Called as the scene transitions from the background to the foreground. 48 | // Use this method to undo the changes made on entering the background. 49 | } 50 | 51 | func sceneDidEnterBackground(_: UIScene) { 52 | // Called as the scene transitions from the foreground to the background. 53 | // Use this method to save data, release shared resources, and store enough scene-specific state information 54 | // to restore the scene back to its current state. 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /TodoMVC/TodoViewModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewModel.swift 3 | // TodoMVC 4 | // 5 | // Created by Ryan Ashcraft on 7/9/19. 6 | // Copyright © 2019 Ryan Ashcraft. All rights reserved. 7 | // 8 | 9 | import Combine 10 | import SwiftUI 11 | 12 | struct TodoItem: Identifiable { 13 | let id: UUID 14 | var isCompleted: Bool 15 | var title: String 16 | } 17 | 18 | final class TodoViewModel: ObservableObject { 19 | var areAllCompleted: Bool { 20 | items.count - incompleteCount == items.count 21 | } 22 | 23 | var incompleteCount: Int = 0 24 | var completeCount: Int = 0 25 | 26 | @Published var items: [TodoItem] = [] { 27 | didSet { 28 | incompleteCount = items.filter { !$0.isCompleted }.count 29 | completeCount = items.count - incompleteCount 30 | } 31 | } 32 | 33 | func createTodo(title: String) { 34 | items.append(TodoItem( 35 | id: UUID(), 36 | isCompleted: false, 37 | title: title 38 | )) 39 | } 40 | 41 | func setIsCompleted(itemId: UUID, isCompleted: Bool) { 42 | items = items.map { 43 | if $0.id == itemId { 44 | return TodoItem(id: $0.id, isCompleted: isCompleted, title: $0.title) 45 | } 46 | 47 | return $0 48 | } 49 | } 50 | 51 | func setTitle(itemId: UUID, title: String) { 52 | items = items.map { 53 | if $0.id == itemId { 54 | return TodoItem(id: $0.id, isCompleted: $0.isCompleted, title: title) 55 | } 56 | 57 | return $0 58 | } 59 | } 60 | 61 | func toggleAllCompleted() { 62 | if areAllCompleted { 63 | items = items.map { 64 | TodoItem(id: $0.id, isCompleted: false, title: $0.title) 65 | } 66 | } else { 67 | items = items.map { 68 | TodoItem(id: $0.id, isCompleted: true, title: $0.title) 69 | } 70 | } 71 | } 72 | 73 | func removeItem(itemId: UUID) { 74 | items = items.filter { $0.id != itemId } 75 | } 76 | 77 | func clearCompleted() { 78 | items = items.filter { !$0.isCompleted } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ryanashcraft/SwiftUI-TodoMVC/aebb236cb00e07c94589598e61eee8d9d58c2d95/screenshot.png --------------------------------------------------------------------------------