├── Images ├── SS_01.png ├── SS_02.png ├── SS_03.png ├── SS_04.png ├── demo.gif ├── pr_source0.png ├── pr_source1.png ├── pr_source2.png └── pr_source3.png ├── README.md ├── TaskApplication.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata └── TaskApplication ├── AppDelegate.swift ├── Base.lproj ├── LaunchScreen.xib └── Main.storyboard ├── Images.xcassets ├── AppIcon.appiconset │ ├── Contents.json │ ├── Icon-60@2x.png │ ├── Icon-60@3x.png │ ├── Icon-Small-40@2x.png │ ├── Icon-Small-40@3x.png │ ├── Icon-Small@2x.png │ └── Icon-Small@3x.png ├── LaunchImage.launchimage │ ├── Contents.json │ ├── iphone4_ios7.png │ └── iphone5_ios7.png ├── create_new-50.imageset │ ├── Contents.json │ ├── create_new-25.png │ ├── create_new-32.png │ └── create_new-50.png ├── first.imageset │ ├── Contents.json │ └── first.pdf ├── iphone4_ios7.imageset │ ├── Contents.json │ └── iphone4_ios7.png ├── report_card-50.imageset │ ├── Contents.json │ ├── report_card-25.png │ ├── report_card-32.png │ └── report_card-50.png └── second.imageset │ ├── Contents.json │ └── second.pdf ├── Info.plist ├── TableViewController.swift ├── Task+CoreDataClass.swift ├── Task+CoreDataProperties.swift ├── TaskApplication.xcdatamodeld └── TaskApplication.xcdatamodel │ └── contents ├── TaskDetailViewController.swift ├── TaskManager.swift └── TaskPersistence.swift /Images/SS_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/Images/SS_01.png -------------------------------------------------------------------------------- /Images/SS_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/Images/SS_02.png -------------------------------------------------------------------------------- /Images/SS_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/Images/SS_03.png -------------------------------------------------------------------------------- /Images/SS_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/Images/SS_04.png -------------------------------------------------------------------------------- /Images/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/Images/demo.gif -------------------------------------------------------------------------------- /Images/pr_source0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/Images/pr_source0.png -------------------------------------------------------------------------------- /Images/pr_source1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/Images/pr_source1.png -------------------------------------------------------------------------------- /Images/pr_source2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/Images/pr_source2.png -------------------------------------------------------------------------------- /Images/pr_source3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/Images/pr_source3.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Task App for Swift that Persist Data with Core Data (iOS) 2 | ================ 3 | 4 | ## Updated for Xcode 10 with Swift 4.2 5 | 6 | Originally by: [Michael Crump](http://twitter.com/mbcrump) 7 | Updates for Xcode 10 with Swift 4.2 by David Phillip Oster 8 | 9 | The original blog post for this article can be found [here,](http://developer.telerik.com/featured/creating-task-application-ios-using-swift/) but it does not include some of the cosmetic tweaks that this version has, nor does it persist data. If you are looking for a simple example of creating a Task app then check my my other [repo.](https://github.com/mbcrump/TasksForSwift) 10 | 11 | Below is a demo from the app that is in the AppStore: 12 | 13 | ![image](https://github.com/mbcrump/TasksForSwiftWithPersistingData/blob/master/Images/demo.gif) 14 | 15 | [Here is the app in the AppStore](https://itunes.apple.com/us/app/task-application/id960435759?ls=1&mt=8) 16 | 17 | ## Oster's comments: 18 | 19 | I took advantage of Xcode's 'Generated NSManagedObjects subclasses' menu command to directly access the Core Data `Task` object. I fixed the appDelegate methods that the operating system was not calling. I removed the do-nothing tests directory and target. I added [sumitmukhija](https://github.com/sumitmukhija)'s U.I. for denoting a completed task, but I also connected it through to the underlying data model. The original app had no way to update an existing record. Added. 20 | 21 | #### Here is Michael Crump's contact info 22 | 23 | [Twitter](http://twitter.com/mbcrump) 24 | 25 | [Blog](http://michaelcrump.net) 26 | 27 | [About Me](http://about.me/mbcrump) 28 | -------------------------------------------------------------------------------- /TaskApplication.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 63C79C05221CEE6700159B4D /* Task+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63C79C03221CEE6700159B4D /* Task+CoreDataClass.swift */; }; 11 | 63C79C06221CEE6700159B4D /* Task+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63C79C04221CEE6700159B4D /* Task+CoreDataProperties.swift */; }; 12 | 8685C2211A6F503100F5CE9F /* TaskPersistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8685C2201A6F503100F5CE9F /* TaskPersistence.swift */; }; 13 | 8685C2261A6F550A00F5CE9F /* TaskApplication.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 8685C2241A6F550A00F5CE9F /* TaskApplication.xcdatamodeld */; }; 14 | 86FF5BB31A6D65FB00A017A1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86FF5BB21A6D65FB00A017A1 /* AppDelegate.swift */; }; 15 | 86FF5BB51A6D65FB00A017A1 /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86FF5BB41A6D65FB00A017A1 /* TableViewController.swift */; }; 16 | 86FF5BB71A6D65FB00A017A1 /* TaskDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86FF5BB61A6D65FB00A017A1 /* TaskDetailViewController.swift */; }; 17 | 86FF5BBA1A6D65FB00A017A1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 86FF5BB81A6D65FB00A017A1 /* Main.storyboard */; }; 18 | 86FF5BBC1A6D65FB00A017A1 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 86FF5BBB1A6D65FB00A017A1 /* Images.xcassets */; }; 19 | 86FF5BBF1A6D65FB00A017A1 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 86FF5BBD1A6D65FB00A017A1 /* LaunchScreen.xib */; }; 20 | 86FF5BD51A6D697400A017A1 /* TaskManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86FF5BD41A6D697400A017A1 /* TaskManager.swift */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXFileReference section */ 24 | 63C79C03221CEE6700159B4D /* Task+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Task+CoreDataClass.swift"; sourceTree = ""; }; 25 | 63C79C04221CEE6700159B4D /* Task+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Task+CoreDataProperties.swift"; sourceTree = ""; }; 26 | 8685C2201A6F503100F5CE9F /* TaskPersistence.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TaskPersistence.swift; sourceTree = ""; }; 27 | 8685C2251A6F550A00F5CE9F /* TaskApplication.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = TaskApplication.xcdatamodel; sourceTree = ""; }; 28 | 86FF5BAD1A6D65FB00A017A1 /* TaskApplication.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TaskApplication.app; sourceTree = BUILT_PRODUCTS_DIR; }; 29 | 86FF5BB11A6D65FB00A017A1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | 86FF5BB21A6D65FB00A017A1 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 31 | 86FF5BB41A6D65FB00A017A1 /* TableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = ""; }; 32 | 86FF5BB61A6D65FB00A017A1 /* TaskDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskDetailViewController.swift; sourceTree = ""; }; 33 | 86FF5BB91A6D65FB00A017A1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 34 | 86FF5BBB1A6D65FB00A017A1 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 35 | 86FF5BBE1A6D65FB00A017A1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 36 | 86FF5BD41A6D697400A017A1 /* TaskManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TaskManager.swift; sourceTree = ""; }; 37 | /* End PBXFileReference section */ 38 | 39 | /* Begin PBXFrameworksBuildPhase section */ 40 | 86FF5BAA1A6D65FB00A017A1 /* Frameworks */ = { 41 | isa = PBXFrameworksBuildPhase; 42 | buildActionMask = 2147483647; 43 | files = ( 44 | ); 45 | runOnlyForDeploymentPostprocessing = 0; 46 | }; 47 | /* End PBXFrameworksBuildPhase section */ 48 | 49 | /* Begin PBXGroup section */ 50 | 86FF5BA41A6D65FB00A017A1 = { 51 | isa = PBXGroup; 52 | children = ( 53 | 86FF5BAF1A6D65FB00A017A1 /* TaskApplication */, 54 | 86FF5BAE1A6D65FB00A017A1 /* Products */, 55 | ); 56 | sourceTree = ""; 57 | }; 58 | 86FF5BAE1A6D65FB00A017A1 /* Products */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 86FF5BAD1A6D65FB00A017A1 /* TaskApplication.app */, 62 | ); 63 | name = Products; 64 | sourceTree = ""; 65 | }; 66 | 86FF5BAF1A6D65FB00A017A1 /* TaskApplication */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | 86FF5BB21A6D65FB00A017A1 /* AppDelegate.swift */, 70 | 86FF5BB41A6D65FB00A017A1 /* TableViewController.swift */, 71 | 86FF5BB61A6D65FB00A017A1 /* TaskDetailViewController.swift */, 72 | 86FF5BB81A6D65FB00A017A1 /* Main.storyboard */, 73 | 86FF5BBB1A6D65FB00A017A1 /* Images.xcassets */, 74 | 86FF5BBD1A6D65FB00A017A1 /* LaunchScreen.xib */, 75 | 86FF5BB01A6D65FB00A017A1 /* Supporting Files */, 76 | 86FF5BD41A6D697400A017A1 /* TaskManager.swift */, 77 | 8685C2201A6F503100F5CE9F /* TaskPersistence.swift */, 78 | 8685C2241A6F550A00F5CE9F /* TaskApplication.xcdatamodeld */, 79 | ); 80 | path = TaskApplication; 81 | sourceTree = ""; 82 | }; 83 | 86FF5BB01A6D65FB00A017A1 /* Supporting Files */ = { 84 | isa = PBXGroup; 85 | children = ( 86 | 63C79C03221CEE6700159B4D /* Task+CoreDataClass.swift */, 87 | 63C79C04221CEE6700159B4D /* Task+CoreDataProperties.swift */, 88 | 86FF5BB11A6D65FB00A017A1 /* Info.plist */, 89 | ); 90 | name = "Supporting Files"; 91 | sourceTree = ""; 92 | }; 93 | /* End PBXGroup section */ 94 | 95 | /* Begin PBXNativeTarget section */ 96 | 86FF5BAC1A6D65FB00A017A1 /* TaskApplication */ = { 97 | isa = PBXNativeTarget; 98 | buildConfigurationList = 86FF5BCE1A6D65FB00A017A1 /* Build configuration list for PBXNativeTarget "TaskApplication" */; 99 | buildPhases = ( 100 | 86FF5BA91A6D65FB00A017A1 /* Sources */, 101 | 86FF5BAA1A6D65FB00A017A1 /* Frameworks */, 102 | 86FF5BAB1A6D65FB00A017A1 /* Resources */, 103 | ); 104 | buildRules = ( 105 | ); 106 | dependencies = ( 107 | ); 108 | name = TaskApplication; 109 | productName = TaskApplication; 110 | productReference = 86FF5BAD1A6D65FB00A017A1 /* TaskApplication.app */; 111 | productType = "com.apple.product-type.application"; 112 | }; 113 | /* End PBXNativeTarget section */ 114 | 115 | /* Begin PBXProject section */ 116 | 86FF5BA51A6D65FB00A017A1 /* Project object */ = { 117 | isa = PBXProject; 118 | attributes = { 119 | LastSwiftMigration = 0700; 120 | LastSwiftUpdateCheck = 0700; 121 | LastUpgradeCheck = 0700; 122 | ORGANIZATIONNAME = "Michael Crump"; 123 | TargetAttributes = { 124 | 86FF5BAC1A6D65FB00A017A1 = { 125 | CreatedOnToolsVersion = 6.1.1; 126 | LastSwiftMigration = 1010; 127 | }; 128 | }; 129 | }; 130 | buildConfigurationList = 86FF5BA81A6D65FB00A017A1 /* Build configuration list for PBXProject "TaskApplication" */; 131 | compatibilityVersion = "Xcode 3.2"; 132 | developmentRegion = English; 133 | hasScannedForEncodings = 0; 134 | knownRegions = ( 135 | en, 136 | Base, 137 | ); 138 | mainGroup = 86FF5BA41A6D65FB00A017A1; 139 | productRefGroup = 86FF5BAE1A6D65FB00A017A1 /* Products */; 140 | projectDirPath = ""; 141 | projectRoot = ""; 142 | targets = ( 143 | 86FF5BAC1A6D65FB00A017A1 /* TaskApplication */, 144 | ); 145 | }; 146 | /* End PBXProject section */ 147 | 148 | /* Begin PBXResourcesBuildPhase section */ 149 | 86FF5BAB1A6D65FB00A017A1 /* Resources */ = { 150 | isa = PBXResourcesBuildPhase; 151 | buildActionMask = 2147483647; 152 | files = ( 153 | 86FF5BBA1A6D65FB00A017A1 /* Main.storyboard in Resources */, 154 | 86FF5BBF1A6D65FB00A017A1 /* LaunchScreen.xib in Resources */, 155 | 86FF5BBC1A6D65FB00A017A1 /* Images.xcassets in Resources */, 156 | ); 157 | runOnlyForDeploymentPostprocessing = 0; 158 | }; 159 | /* End PBXResourcesBuildPhase section */ 160 | 161 | /* Begin PBXSourcesBuildPhase section */ 162 | 86FF5BA91A6D65FB00A017A1 /* Sources */ = { 163 | isa = PBXSourcesBuildPhase; 164 | buildActionMask = 2147483647; 165 | files = ( 166 | 86FF5BB71A6D65FB00A017A1 /* TaskDetailViewController.swift in Sources */, 167 | 63C79C05221CEE6700159B4D /* Task+CoreDataClass.swift in Sources */, 168 | 86FF5BB31A6D65FB00A017A1 /* AppDelegate.swift in Sources */, 169 | 86FF5BD51A6D697400A017A1 /* TaskManager.swift in Sources */, 170 | 8685C2211A6F503100F5CE9F /* TaskPersistence.swift in Sources */, 171 | 86FF5BB51A6D65FB00A017A1 /* TableViewController.swift in Sources */, 172 | 8685C2261A6F550A00F5CE9F /* TaskApplication.xcdatamodeld in Sources */, 173 | 63C79C06221CEE6700159B4D /* Task+CoreDataProperties.swift in Sources */, 174 | ); 175 | runOnlyForDeploymentPostprocessing = 0; 176 | }; 177 | /* End PBXSourcesBuildPhase section */ 178 | 179 | /* Begin PBXVariantGroup section */ 180 | 86FF5BB81A6D65FB00A017A1 /* Main.storyboard */ = { 181 | isa = PBXVariantGroup; 182 | children = ( 183 | 86FF5BB91A6D65FB00A017A1 /* Base */, 184 | ); 185 | name = Main.storyboard; 186 | sourceTree = ""; 187 | }; 188 | 86FF5BBD1A6D65FB00A017A1 /* LaunchScreen.xib */ = { 189 | isa = PBXVariantGroup; 190 | children = ( 191 | 86FF5BBE1A6D65FB00A017A1 /* Base */, 192 | ); 193 | name = LaunchScreen.xib; 194 | sourceTree = ""; 195 | }; 196 | /* End PBXVariantGroup section */ 197 | 198 | /* Begin XCBuildConfiguration section */ 199 | 86FF5BCC1A6D65FB00A017A1 /* Debug */ = { 200 | isa = XCBuildConfiguration; 201 | buildSettings = { 202 | ALWAYS_SEARCH_USER_PATHS = NO; 203 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 204 | CLANG_CXX_LIBRARY = "libc++"; 205 | CLANG_ENABLE_MODULES = YES; 206 | CLANG_ENABLE_OBJC_ARC = YES; 207 | CLANG_WARN_BOOL_CONVERSION = YES; 208 | CLANG_WARN_CONSTANT_CONVERSION = YES; 209 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 210 | CLANG_WARN_EMPTY_BODY = YES; 211 | CLANG_WARN_ENUM_CONVERSION = YES; 212 | CLANG_WARN_INT_CONVERSION = YES; 213 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 214 | CLANG_WARN_UNREACHABLE_CODE = YES; 215 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 216 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 217 | COPY_PHASE_STRIP = NO; 218 | ENABLE_STRICT_OBJC_MSGSEND = YES; 219 | ENABLE_TESTABILITY = YES; 220 | GCC_C_LANGUAGE_STANDARD = gnu99; 221 | GCC_DYNAMIC_NO_PIC = NO; 222 | GCC_OPTIMIZATION_LEVEL = 0; 223 | GCC_PREPROCESSOR_DEFINITIONS = ( 224 | "DEBUG=1", 225 | "$(inherited)", 226 | ); 227 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 228 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 229 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 230 | GCC_WARN_UNDECLARED_SELECTOR = YES; 231 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 232 | GCC_WARN_UNUSED_FUNCTION = YES; 233 | GCC_WARN_UNUSED_VARIABLE = YES; 234 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 235 | MTL_ENABLE_DEBUG_INFO = YES; 236 | ONLY_ACTIVE_ARCH = YES; 237 | SDKROOT = iphoneos; 238 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 239 | SWIFT_PRECOMPILE_BRIDGING_HEADER = NO; 240 | SWIFT_VERSION = 4.2; 241 | }; 242 | name = Debug; 243 | }; 244 | 86FF5BCD1A6D65FB00A017A1 /* Release */ = { 245 | isa = XCBuildConfiguration; 246 | buildSettings = { 247 | ALWAYS_SEARCH_USER_PATHS = NO; 248 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 249 | CLANG_CXX_LIBRARY = "libc++"; 250 | CLANG_ENABLE_MODULES = YES; 251 | CLANG_ENABLE_OBJC_ARC = YES; 252 | CLANG_WARN_BOOL_CONVERSION = YES; 253 | CLANG_WARN_CONSTANT_CONVERSION = YES; 254 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 255 | CLANG_WARN_EMPTY_BODY = YES; 256 | CLANG_WARN_ENUM_CONVERSION = YES; 257 | CLANG_WARN_INT_CONVERSION = YES; 258 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 259 | CLANG_WARN_UNREACHABLE_CODE = YES; 260 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 261 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 262 | COPY_PHASE_STRIP = YES; 263 | ENABLE_NS_ASSERTIONS = NO; 264 | ENABLE_STRICT_OBJC_MSGSEND = YES; 265 | GCC_C_LANGUAGE_STANDARD = gnu99; 266 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 267 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 268 | GCC_WARN_UNDECLARED_SELECTOR = YES; 269 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 270 | GCC_WARN_UNUSED_FUNCTION = YES; 271 | GCC_WARN_UNUSED_VARIABLE = YES; 272 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 273 | MTL_ENABLE_DEBUG_INFO = NO; 274 | SDKROOT = iphoneos; 275 | SWIFT_PRECOMPILE_BRIDGING_HEADER = NO; 276 | SWIFT_VERSION = 4.2; 277 | VALIDATE_PRODUCT = YES; 278 | }; 279 | name = Release; 280 | }; 281 | 86FF5BCF1A6D65FB00A017A1 /* Debug */ = { 282 | isa = XCBuildConfiguration; 283 | buildSettings = { 284 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 285 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 286 | CLANG_ENABLE_MODULES = YES; 287 | CODE_SIGN_IDENTITY = "iPhone Developer"; 288 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 289 | INFOPLIST_FILE = TaskApplication/Info.plist; 290 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 291 | PRODUCT_BUNDLE_IDENTIFIER = "net.michaelcrump.$(PRODUCT_NAME:rfc1034identifier)"; 292 | PRODUCT_NAME = "$(TARGET_NAME)"; 293 | PROVISIONING_PROFILE = ""; 294 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 295 | SWIFT_VERSION = 4.2; 296 | }; 297 | name = Debug; 298 | }; 299 | 86FF5BD01A6D65FB00A017A1 /* Release */ = { 300 | isa = XCBuildConfiguration; 301 | buildSettings = { 302 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 303 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 304 | CLANG_ENABLE_MODULES = YES; 305 | CODE_SIGN_IDENTITY = "iPhone Developer"; 306 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 307 | INFOPLIST_FILE = TaskApplication/Info.plist; 308 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 309 | PRODUCT_BUNDLE_IDENTIFIER = "net.michaelcrump.$(PRODUCT_NAME:rfc1034identifier)"; 310 | PRODUCT_NAME = "$(TARGET_NAME)"; 311 | PROVISIONING_PROFILE = ""; 312 | SWIFT_VERSION = 4.2; 313 | }; 314 | name = Release; 315 | }; 316 | /* End XCBuildConfiguration section */ 317 | 318 | /* Begin XCConfigurationList section */ 319 | 86FF5BA81A6D65FB00A017A1 /* Build configuration list for PBXProject "TaskApplication" */ = { 320 | isa = XCConfigurationList; 321 | buildConfigurations = ( 322 | 86FF5BCC1A6D65FB00A017A1 /* Debug */, 323 | 86FF5BCD1A6D65FB00A017A1 /* Release */, 324 | ); 325 | defaultConfigurationIsVisible = 0; 326 | defaultConfigurationName = Release; 327 | }; 328 | 86FF5BCE1A6D65FB00A017A1 /* Build configuration list for PBXNativeTarget "TaskApplication" */ = { 329 | isa = XCConfigurationList; 330 | buildConfigurations = ( 331 | 86FF5BCF1A6D65FB00A017A1 /* Debug */, 332 | 86FF5BD01A6D65FB00A017A1 /* Release */, 333 | ); 334 | defaultConfigurationIsVisible = 0; 335 | defaultConfigurationName = Release; 336 | }; 337 | /* End XCConfigurationList section */ 338 | 339 | /* Begin XCVersionGroup section */ 340 | 8685C2241A6F550A00F5CE9F /* TaskApplication.xcdatamodeld */ = { 341 | isa = XCVersionGroup; 342 | children = ( 343 | 8685C2251A6F550A00F5CE9F /* TaskApplication.xcdatamodel */, 344 | ); 345 | currentVersion = 8685C2251A6F550A00F5CE9F /* TaskApplication.xcdatamodel */; 346 | path = TaskApplication.xcdatamodeld; 347 | sourceTree = ""; 348 | versionGroupType = wrapper.xcdatamodel; 349 | }; 350 | /* End XCVersionGroup section */ 351 | }; 352 | rootObject = 86FF5BA51A6D65FB00A017A1 /* Project object */; 353 | } 354 | -------------------------------------------------------------------------------- /TaskApplication.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TaskApplication/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // TaskApplication 4 | // 5 | // Created by Michael Crump 6 | // Copyright (c) 2015 Michael Crump. All rights reserved. 7 | // Changes by David Phillip Oster on 2/17/19. 8 | // Added isDone BOOL here and in data model 9 | // Rewrote Data Model to use just Core Data, without the unnecessary Dictionary 10 | 11 | import UIKit 12 | import CoreData 13 | 14 | 15 | @UIApplicationMain 16 | class AppDelegate: UIResponder, UIApplicationDelegate { 17 | 18 | var window: UIWindow? 19 | 20 | 21 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]?) -> Bool { 22 | //UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.Default 23 | return true 24 | } 25 | 26 | func applicationWillResignActive(_ application: UIApplication) { 27 | saveContext() 28 | } 29 | 30 | // MARK: - Core Data stack 31 | 32 | lazy var applicationDocumentsDirectory: NSURL = { 33 | // The directory the application uses to store the Core Data store file. This code uses a directory named "net.michaelcrump.CoreDataSample" in the application's documents Application Support directory. 34 | let urls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) 35 | return urls[urls.count-1] as NSURL 36 | }() 37 | 38 | lazy var managedObjectModel: NSManagedObjectModel = { 39 | // The managed object model for the application. This property is not optional. It is a fatal error for the application not to be able to find and load its model. 40 | let modelURL = Bundle.main.url(forResource: "TaskApplication", withExtension: "momd")! 41 | return NSManagedObjectModel(contentsOf: modelURL)! 42 | }() 43 | 44 | lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator = { 45 | // The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail. 46 | // Create the coordinator and store 47 | let coordinator = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel) 48 | let url = self.applicationDocumentsDirectory.appendingPathComponent("SingleViewCoreData.sqlite") 49 | var failureReason = "There was an error creating or loading the application's saved data." 50 | do { 51 | try coordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: nil) 52 | } catch { 53 | // Report any error we got. 54 | var dict = [String: AnyObject]() 55 | dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data" as AnyObject 56 | dict[NSLocalizedFailureReasonErrorKey] = failureReason as AnyObject 57 | 58 | dict[NSUnderlyingErrorKey] = error as NSError 59 | let wrappedError = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict) 60 | // Replace this with code to handle the error appropriately. 61 | // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 62 | NSLog("Unresolved error \(wrappedError), \(wrappedError.userInfo)") 63 | abort() 64 | } 65 | 66 | return coordinator 67 | }() 68 | 69 | lazy var managedObjectContext: NSManagedObjectContext = { 70 | // Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) This property is optional since there are legitimate error conditions that could cause the creation of the context to fail. 71 | let coordinator = self.persistentStoreCoordinator 72 | var managedObjectContext = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType) 73 | managedObjectContext.persistentStoreCoordinator = coordinator 74 | return managedObjectContext 75 | }() 76 | 77 | // MARK: - Core Data Saving support 78 | 79 | func saveContext () { 80 | if managedObjectContext.hasChanges { 81 | do { 82 | try managedObjectContext.save() 83 | } catch { 84 | // Replace this implementation with code to handle the error appropriately. 85 | // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 86 | let nserror = error as NSError 87 | NSLog("Unresolved error \(nserror), \(nserror.userInfo)") 88 | abort() 89 | } 90 | } 91 | } 92 | } 93 | 94 | -------------------------------------------------------------------------------- /TaskApplication/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 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 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /TaskApplication/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 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 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 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /TaskApplication/Images.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 | "size" : "29x29", 15 | "idiom" : "iphone", 16 | "filename" : "Icon-Small@2x.png", 17 | "scale" : "2x" 18 | }, 19 | { 20 | "size" : "29x29", 21 | "idiom" : "iphone", 22 | "filename" : "Icon-Small@3x.png", 23 | "scale" : "3x" 24 | }, 25 | { 26 | "size" : "40x40", 27 | "idiom" : "iphone", 28 | "filename" : "Icon-Small-40@2x.png", 29 | "scale" : "2x" 30 | }, 31 | { 32 | "size" : "40x40", 33 | "idiom" : "iphone", 34 | "filename" : "Icon-Small-40@3x.png", 35 | "scale" : "3x" 36 | }, 37 | { 38 | "size" : "60x60", 39 | "idiom" : "iphone", 40 | "filename" : "Icon-60@2x.png", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "size" : "60x60", 45 | "idiom" : "iphone", 46 | "filename" : "Icon-60@3x.png", 47 | "scale" : "3x" 48 | }, 49 | { 50 | "idiom" : "ios-marketing", 51 | "size" : "1024x1024", 52 | "scale" : "1x" 53 | } 54 | ], 55 | "info" : { 56 | "version" : 1, 57 | "author" : "xcode" 58 | } 59 | } -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/AppIcon.appiconset/Icon-60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/TaskApplication/Images.xcassets/AppIcon.appiconset/Icon-60@2x.png -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/AppIcon.appiconset/Icon-60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/TaskApplication/Images.xcassets/AppIcon.appiconset/Icon-60@3x.png -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/AppIcon.appiconset/Icon-Small-40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/TaskApplication/Images.xcassets/AppIcon.appiconset/Icon-Small-40@2x.png -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/AppIcon.appiconset/Icon-Small-40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/TaskApplication/Images.xcassets/AppIcon.appiconset/Icon-Small-40@3x.png -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/AppIcon.appiconset/Icon-Small@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/TaskApplication/Images.xcassets/AppIcon.appiconset/Icon-Small@2x.png -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/AppIcon.appiconset/Icon-Small@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/TaskApplication/Images.xcassets/AppIcon.appiconset/Icon-Small@3x.png -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "filename" : "iphone4_ios7.png", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "extent" : "full-screen", 13 | "idiom" : "iphone", 14 | "subtype" : "retina4", 15 | "filename" : "iphone5_ios7.png", 16 | "minimum-system-version" : "7.0", 17 | "orientation" : "portrait", 18 | "scale" : "2x" 19 | } 20 | ], 21 | "info" : { 22 | "version" : 1, 23 | "author" : "xcode" 24 | } 25 | } -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/LaunchImage.launchimage/iphone4_ios7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/TaskApplication/Images.xcassets/LaunchImage.launchimage/iphone4_ios7.png -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/LaunchImage.launchimage/iphone5_ios7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/TaskApplication/Images.xcassets/LaunchImage.launchimage/iphone5_ios7.png -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/create_new-50.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x", 6 | "filename" : "create_new-25.png" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x", 11 | "filename" : "create_new-32.png" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "scale" : "3x", 16 | "filename" : "create_new-50.png" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/create_new-50.imageset/create_new-25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/TaskApplication/Images.xcassets/create_new-50.imageset/create_new-25.png -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/create_new-50.imageset/create_new-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/TaskApplication/Images.xcassets/create_new-50.imageset/create_new-32.png -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/create_new-50.imageset/create_new-50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/TaskApplication/Images.xcassets/create_new-50.imageset/create_new-50.png -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/first.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "first.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/first.imageset/first.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/TaskApplication/Images.xcassets/first.imageset/first.pdf -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/iphone4_ios7.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x", 6 | "filename" : "iphone4_ios7.png" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/iphone4_ios7.imageset/iphone4_ios7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/TaskApplication/Images.xcassets/iphone4_ios7.imageset/iphone4_ios7.png -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/report_card-50.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x", 6 | "filename" : "report_card-25.png" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x", 11 | "filename" : "report_card-32.png" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "scale" : "3x", 16 | "filename" : "report_card-50.png" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/report_card-50.imageset/report_card-25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/TaskApplication/Images.xcassets/report_card-50.imageset/report_card-25.png -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/report_card-50.imageset/report_card-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/TaskApplication/Images.xcassets/report_card-50.imageset/report_card-32.png -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/report_card-50.imageset/report_card-50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/TaskApplication/Images.xcassets/report_card-50.imageset/report_card-50.png -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/second.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "second.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /TaskApplication/Images.xcassets/second.imageset/second.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcrump/TasksForSwiftWithPersistingData/a6610d1eda88c9105999371ff40fa211e0f661ba/TaskApplication/Images.xcassets/second.imageset/second.pdf -------------------------------------------------------------------------------- /TaskApplication/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.2 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UIStatusBarHidden 34 | 35 | UIStatusBarTintParameters 36 | 37 | UINavigationBar 38 | 39 | Style 40 | UIBarStyleDefault 41 | Translucent 42 | 43 | 44 | 45 | UISupportedInterfaceOrientations 46 | 47 | UIInterfaceOrientationPortrait 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /TaskApplication/TableViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TableViewController.swift 3 | // TaskApplication 4 | // 5 | // Created by Michael Crump 6 | // Copyright (c) 2015 Michael Crump. All rights reserved. 7 | // Changes by David Phillip Oster on 2/17/19. 8 | // Added isDone BOOL here and in data model 9 | // Rewrote Data Model to use just Core Data, without the unnecessary Dictionary 10 | 11 | import UIKit 12 | 13 | class TableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource 14 | { 15 | 16 | 17 | @IBOutlet var tblTasks : UITableView! 18 | 19 | override func viewWillAppear(_ animated: Bool) { 20 | self.tblTasks.reloadData() 21 | } 22 | 23 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{ 24 | return taskMgr.tasks.count 25 | } 26 | 27 | //Define how our cells look - 2 lines a heading and a subtitle 28 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 29 | let cell: UITableViewCell = UITableViewCell(style: UITableViewCell.CellStyle.subtitle, reuseIdentifier: "Default Tasks") 30 | 31 | //Assign the contents of our var "items" to the textLabel of each cell 32 | let task = taskMgr.tasks[indexPath.row] 33 | let text = NSMutableAttributedString(string: task.name ?? "") 34 | if task.isDone?.boolValue ?? false { 35 | text.addAttribute(.strikethroughStyle, value: 1, range: NSMakeRange(0, text.length)) 36 | } 37 | cell.textLabel!.attributedText = text 38 | cell.detailTextLabel!.text = task.desc 39 | 40 | return cell 41 | } 42 | 43 | func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { 44 | if editingStyle == UITableViewCell.EditingStyle.delete { 45 | taskMgr.removeTask(index: indexPath.row) 46 | tblTasks.reloadData() 47 | } 48 | } 49 | 50 | func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){ 51 | let isDone = taskMgr.tasks[indexPath.row].isDone?.boolValue ?? false 52 | taskMgr.tasks[indexPath.row].isDone = NSNumber(booleanLiteral: !isDone) 53 | tableView.deselectRow(at: indexPath, animated: true) 54 | tableView.reloadRows(at: [indexPath], with: .fade) 55 | } 56 | 57 | } 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /TaskApplication/Task+CoreDataClass.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import CoreData 3 | 4 | @objc(Task) 5 | public class Task: NSManagedObject { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /TaskApplication/Task+CoreDataProperties.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import CoreData 3 | 4 | extension Task { 5 | 6 | @nonobjc public class func fetchRequest() -> NSFetchRequest { 7 | return NSFetchRequest(entityName: "Task") 8 | } 9 | 10 | @NSManaged public var desc: String? 11 | @NSManaged public var isDone: NSNumber? 12 | @NSManaged public var name: String? 13 | 14 | } 15 | -------------------------------------------------------------------------------- /TaskApplication/TaskApplication.xcdatamodeld/TaskApplication.xcdatamodel/contents: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /TaskApplication/TaskDetailViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TaskDetailViewController.swift 3 | // TaskApplication 4 | // 5 | // Created by Michael Crump 6 | // Copyright (c) 2015 Michael Crump. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class TaskDetailViewController: UIViewController, UITextFieldDelegate { 12 | 13 | @IBOutlet var txtTask: UITextField! 14 | @IBOutlet var txtDesc: UITextField! 15 | 16 | //Button Clicked 17 | @IBAction func btnAddTask(sender : UIButton){ 18 | if (txtTask.text == ""){ 19 | // Task Title is blank, do not add a record 20 | } else { 21 | // add record 22 | let name: String = txtTask.text! 23 | let description: String = txtDesc.text! 24 | taskMgr.addTask(name: name, desc: description, isDone: false) 25 | 26 | // dismiss keyboard and reset fields 27 | self.view.endEditing(true) 28 | txtTask.text = nil 29 | txtDesc.text = nil 30 | 31 | } 32 | } 33 | 34 | override func touchesBegan(_ touches: Set, with event: UIEvent?) { 35 | self.view.endEditing(true) 36 | } 37 | 38 | func textFieldShouldReturn(_ textField: UITextField) -> Bool{ 39 | textField.resignFirstResponder() 40 | return true 41 | } 42 | 43 | } 44 | 45 | -------------------------------------------------------------------------------- /TaskApplication/TaskManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TaskManager.swift 3 | // TaskApplication 4 | // 5 | // Created by Michael Crump 6 | // Copyright (c) 2015 Michael Crump. All rights reserved. 7 | // Changes by David Phillip Oster on 2/17/19. 8 | // Added isDone BOOL here and in data model 9 | // Rewrote Data Model to use just Core Data, without the unnecessary Dictionary 10 | 11 | import UIKit 12 | 13 | var taskMgr: TaskManager = TaskManager() 14 | 15 | class TaskManager: NSObject { 16 | var tasks: [Task] 17 | var taskPersistence: TaskPersistence 18 | 19 | override init() { 20 | taskPersistence = TaskPersistence() 21 | tasks = taskPersistence.list() 22 | } 23 | 24 | func addTask(name:String, desc: String, isDone: Bool) { 25 | if let task = taskPersistence.construct() { 26 | task.desc = desc 27 | task.name = name 28 | task.isDone = isDone as NSNumber 29 | tasks.append(task) 30 | } 31 | } 32 | 33 | func removeTask(index: Int) { 34 | let task = tasks[index] 35 | if taskPersistence.remove(instance: task) { 36 | tasks.remove(at: index) 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /TaskApplication/TaskPersistence.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PersistenceHelper.swift 3 | // TaskApplication 4 | // 5 | // Created by Michael Crump 6 | // Copyright (c) 2015 Michael Crump. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import CoreData 11 | 12 | class TaskPersistence: NSObject { 13 | 14 | var appDel: AppDelegate 15 | var context: NSManagedObjectContext; 16 | 17 | override init() { 18 | appDel = (UIApplication.shared.delegate as! AppDelegate) 19 | context = appDel.managedObjectContext 20 | } 21 | 22 | func construct()-> Task? { 23 | return NSEntityDescription.insertNewObject(forEntityName: "Task", into: context) as? Task 24 | } 25 | 26 | func list() -> [Task] { 27 | let request = NSFetchRequest(entityName: "Task") 28 | request.returnsObjectsAsFaults = false; 29 | let results: [Task] = try! context.fetch(request) as! [Task] 30 | return results 31 | } 32 | 33 | func remove(instance: NSManagedObject) -> Bool { 34 | context.delete(instance) 35 | do { 36 | try context.save() 37 | } catch _ { 38 | return false 39 | } 40 | return true 41 | } 42 | 43 | } 44 | --------------------------------------------------------------------------------