├── LICENSE ├── README.md ├── SwiftUIAppWithCoreData.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcuserdata │ └── barm.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist └── SwiftUIAppWithCoreData ├── Assets.xcassets ├── AccentColor.colorset │ └── Contents.json ├── AppIcon.appiconset │ └── Contents.json └── Contents.json ├── ContentView.swift ├── Info.plist ├── MyModel.xcdatamodeld └── MyModel.xcdatamodel │ └── contents ├── PersistentCloudKitContainer.swift ├── Preview Content └── Preview Assets.xcassets │ └── Contents.json └── SwiftUIAppWithCoreDataApp.swift /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 bmaciag 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-App-with-Core-Data 2 | Sample XCode 12 iOS App that uses the SwiftUI App Life Cycle with Core Data 3 | -------------------------------------------------------------------------------- /SwiftUIAppWithCoreData.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4311855C24AF489900167670 /* SwiftUIAppWithCoreDataApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4311855B24AF489900167670 /* SwiftUIAppWithCoreDataApp.swift */; }; 11 | 4311855E24AF489900167670 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4311855D24AF489900167670 /* ContentView.swift */; }; 12 | 4311856024AF489A00167670 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4311855F24AF489A00167670 /* Assets.xcassets */; }; 13 | 4311856324AF489A00167670 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4311856224AF489A00167670 /* Preview Assets.xcassets */; }; 14 | 4311856C24AF4CF200167670 /* MyModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 4311856A24AF4CF200167670 /* MyModel.xcdatamodeld */; }; 15 | 43564AAD24B23B5200767048 /* PersistentCloudKitContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43564AAC24B23B5200767048 /* PersistentCloudKitContainer.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 4311855824AF489900167670 /* SwiftUIAppWithCoreData.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwiftUIAppWithCoreData.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | 4311855B24AF489900167670 /* SwiftUIAppWithCoreDataApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIAppWithCoreDataApp.swift; sourceTree = ""; }; 21 | 4311855D24AF489900167670 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 22 | 4311855F24AF489A00167670 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 23 | 4311856224AF489A00167670 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 24 | 4311856424AF489A00167670 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 25 | 4311856B24AF4CF200167670 /* MyModel.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = MyModel.xcdatamodel; sourceTree = ""; }; 26 | 43564AAC24B23B5200767048 /* PersistentCloudKitContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersistentCloudKitContainer.swift; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | 4311855524AF489900167670 /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | 4311854F24AF489900167670 = { 41 | isa = PBXGroup; 42 | children = ( 43 | 4311855A24AF489900167670 /* SwiftUIAppWithCoreData */, 44 | 4311855924AF489900167670 /* Products */, 45 | ); 46 | sourceTree = ""; 47 | }; 48 | 4311855924AF489900167670 /* Products */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | 4311855824AF489900167670 /* SwiftUIAppWithCoreData.app */, 52 | ); 53 | name = Products; 54 | sourceTree = ""; 55 | }; 56 | 4311855A24AF489900167670 /* SwiftUIAppWithCoreData */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | 4311855B24AF489900167670 /* SwiftUIAppWithCoreDataApp.swift */, 60 | 4311855D24AF489900167670 /* ContentView.swift */, 61 | 4311855F24AF489A00167670 /* Assets.xcassets */, 62 | 4311856424AF489A00167670 /* Info.plist */, 63 | 4311856124AF489A00167670 /* Preview Content */, 64 | 4311856A24AF4CF200167670 /* MyModel.xcdatamodeld */, 65 | 43564AAC24B23B5200767048 /* PersistentCloudKitContainer.swift */, 66 | ); 67 | path = SwiftUIAppWithCoreData; 68 | sourceTree = ""; 69 | }; 70 | 4311856124AF489A00167670 /* Preview Content */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | 4311856224AF489A00167670 /* Preview Assets.xcassets */, 74 | ); 75 | path = "Preview Content"; 76 | sourceTree = ""; 77 | }; 78 | /* End PBXGroup section */ 79 | 80 | /* Begin PBXNativeTarget section */ 81 | 4311855724AF489900167670 /* SwiftUIAppWithCoreData */ = { 82 | isa = PBXNativeTarget; 83 | buildConfigurationList = 4311856724AF489A00167670 /* Build configuration list for PBXNativeTarget "SwiftUIAppWithCoreData" */; 84 | buildPhases = ( 85 | 4311855424AF489900167670 /* Sources */, 86 | 4311855524AF489900167670 /* Frameworks */, 87 | 4311855624AF489900167670 /* Resources */, 88 | ); 89 | buildRules = ( 90 | ); 91 | dependencies = ( 92 | ); 93 | name = SwiftUIAppWithCoreData; 94 | productName = SwiftUIAppWithCoreData; 95 | productReference = 4311855824AF489900167670 /* SwiftUIAppWithCoreData.app */; 96 | productType = "com.apple.product-type.application"; 97 | }; 98 | /* End PBXNativeTarget section */ 99 | 100 | /* Begin PBXProject section */ 101 | 4311855024AF489900167670 /* Project object */ = { 102 | isa = PBXProject; 103 | attributes = { 104 | LastSwiftUpdateCheck = 1200; 105 | LastUpgradeCheck = 1200; 106 | TargetAttributes = { 107 | 4311855724AF489900167670 = { 108 | CreatedOnToolsVersion = 12.0; 109 | }; 110 | }; 111 | }; 112 | buildConfigurationList = 4311855324AF489900167670 /* Build configuration list for PBXProject "SwiftUIAppWithCoreData" */; 113 | compatibilityVersion = "Xcode 9.3"; 114 | developmentRegion = en; 115 | hasScannedForEncodings = 0; 116 | knownRegions = ( 117 | en, 118 | Base, 119 | ); 120 | mainGroup = 4311854F24AF489900167670; 121 | productRefGroup = 4311855924AF489900167670 /* Products */; 122 | projectDirPath = ""; 123 | projectRoot = ""; 124 | targets = ( 125 | 4311855724AF489900167670 /* SwiftUIAppWithCoreData */, 126 | ); 127 | }; 128 | /* End PBXProject section */ 129 | 130 | /* Begin PBXResourcesBuildPhase section */ 131 | 4311855624AF489900167670 /* Resources */ = { 132 | isa = PBXResourcesBuildPhase; 133 | buildActionMask = 2147483647; 134 | files = ( 135 | 4311856324AF489A00167670 /* Preview Assets.xcassets in Resources */, 136 | 4311856024AF489A00167670 /* Assets.xcassets in Resources */, 137 | ); 138 | runOnlyForDeploymentPostprocessing = 0; 139 | }; 140 | /* End PBXResourcesBuildPhase section */ 141 | 142 | /* Begin PBXSourcesBuildPhase section */ 143 | 4311855424AF489900167670 /* Sources */ = { 144 | isa = PBXSourcesBuildPhase; 145 | buildActionMask = 2147483647; 146 | files = ( 147 | 4311855E24AF489900167670 /* ContentView.swift in Sources */, 148 | 43564AAD24B23B5200767048 /* PersistentCloudKitContainer.swift in Sources */, 149 | 4311855C24AF489900167670 /* SwiftUIAppWithCoreDataApp.swift in Sources */, 150 | 4311856C24AF4CF200167670 /* MyModel.xcdatamodeld in Sources */, 151 | ); 152 | runOnlyForDeploymentPostprocessing = 0; 153 | }; 154 | /* End PBXSourcesBuildPhase section */ 155 | 156 | /* Begin XCBuildConfiguration section */ 157 | 4311856524AF489A00167670 /* Debug */ = { 158 | isa = XCBuildConfiguration; 159 | buildSettings = { 160 | ALWAYS_SEARCH_USER_PATHS = NO; 161 | CLANG_ANALYZER_NONNULL = YES; 162 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 163 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 164 | CLANG_CXX_LIBRARY = "libc++"; 165 | CLANG_ENABLE_MODULES = YES; 166 | CLANG_ENABLE_OBJC_ARC = YES; 167 | CLANG_ENABLE_OBJC_WEAK = YES; 168 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 169 | CLANG_WARN_BOOL_CONVERSION = YES; 170 | CLANG_WARN_COMMA = YES; 171 | CLANG_WARN_CONSTANT_CONVERSION = YES; 172 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 173 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 174 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 175 | CLANG_WARN_EMPTY_BODY = YES; 176 | CLANG_WARN_ENUM_CONVERSION = YES; 177 | CLANG_WARN_INFINITE_RECURSION = YES; 178 | CLANG_WARN_INT_CONVERSION = YES; 179 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 180 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 181 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 182 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 183 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 184 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 185 | CLANG_WARN_STRICT_PROTOTYPES = YES; 186 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 187 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 188 | CLANG_WARN_UNREACHABLE_CODE = YES; 189 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 190 | COPY_PHASE_STRIP = NO; 191 | DEBUG_INFORMATION_FORMAT = dwarf; 192 | ENABLE_STRICT_OBJC_MSGSEND = YES; 193 | ENABLE_TESTABILITY = YES; 194 | GCC_C_LANGUAGE_STANDARD = gnu11; 195 | GCC_DYNAMIC_NO_PIC = NO; 196 | GCC_NO_COMMON_BLOCKS = YES; 197 | GCC_OPTIMIZATION_LEVEL = 0; 198 | GCC_PREPROCESSOR_DEFINITIONS = ( 199 | "DEBUG=1", 200 | "$(inherited)", 201 | ); 202 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 203 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 204 | GCC_WARN_UNDECLARED_SELECTOR = YES; 205 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 206 | GCC_WARN_UNUSED_FUNCTION = YES; 207 | GCC_WARN_UNUSED_VARIABLE = YES; 208 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 209 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 210 | MTL_FAST_MATH = YES; 211 | ONLY_ACTIVE_ARCH = YES; 212 | SDKROOT = iphoneos; 213 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 214 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 215 | }; 216 | name = Debug; 217 | }; 218 | 4311856624AF489A00167670 /* Release */ = { 219 | isa = XCBuildConfiguration; 220 | buildSettings = { 221 | ALWAYS_SEARCH_USER_PATHS = NO; 222 | CLANG_ANALYZER_NONNULL = YES; 223 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 224 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 225 | CLANG_CXX_LIBRARY = "libc++"; 226 | CLANG_ENABLE_MODULES = YES; 227 | CLANG_ENABLE_OBJC_ARC = YES; 228 | CLANG_ENABLE_OBJC_WEAK = YES; 229 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 230 | CLANG_WARN_BOOL_CONVERSION = YES; 231 | CLANG_WARN_COMMA = YES; 232 | CLANG_WARN_CONSTANT_CONVERSION = YES; 233 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 234 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 235 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 236 | CLANG_WARN_EMPTY_BODY = YES; 237 | CLANG_WARN_ENUM_CONVERSION = YES; 238 | CLANG_WARN_INFINITE_RECURSION = YES; 239 | CLANG_WARN_INT_CONVERSION = YES; 240 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 241 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 242 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 243 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 244 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 245 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 246 | CLANG_WARN_STRICT_PROTOTYPES = YES; 247 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 248 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 249 | CLANG_WARN_UNREACHABLE_CODE = YES; 250 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 251 | COPY_PHASE_STRIP = NO; 252 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 253 | ENABLE_NS_ASSERTIONS = NO; 254 | ENABLE_STRICT_OBJC_MSGSEND = YES; 255 | GCC_C_LANGUAGE_STANDARD = gnu11; 256 | GCC_NO_COMMON_BLOCKS = YES; 257 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 258 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 259 | GCC_WARN_UNDECLARED_SELECTOR = YES; 260 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 261 | GCC_WARN_UNUSED_FUNCTION = YES; 262 | GCC_WARN_UNUSED_VARIABLE = YES; 263 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 264 | MTL_ENABLE_DEBUG_INFO = NO; 265 | MTL_FAST_MATH = YES; 266 | SDKROOT = iphoneos; 267 | SWIFT_COMPILATION_MODE = wholemodule; 268 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 269 | VALIDATE_PRODUCT = YES; 270 | }; 271 | name = Release; 272 | }; 273 | 4311856824AF489A00167670 /* Debug */ = { 274 | isa = XCBuildConfiguration; 275 | buildSettings = { 276 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 277 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 278 | CODE_SIGN_STYLE = Automatic; 279 | DEVELOPMENT_ASSET_PATHS = "\"SwiftUIAppWithCoreData/Preview Content\""; 280 | DEVELOPMENT_TEAM = VX9NFCQJLB; 281 | ENABLE_PREVIEWS = YES; 282 | INFOPLIST_FILE = SwiftUIAppWithCoreData/Info.plist; 283 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 284 | LD_RUNPATH_SEARCH_PATHS = ( 285 | "$(inherited)", 286 | "@executable_path/Frameworks", 287 | ); 288 | PRODUCT_BUNDLE_IDENTIFIER = de.bmaciag.SwiftUIAppWithCoreData; 289 | PRODUCT_NAME = "$(TARGET_NAME)"; 290 | SWIFT_VERSION = 5.0; 291 | TARGETED_DEVICE_FAMILY = "1,2"; 292 | }; 293 | name = Debug; 294 | }; 295 | 4311856924AF489A00167670 /* Release */ = { 296 | isa = XCBuildConfiguration; 297 | buildSettings = { 298 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 299 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 300 | CODE_SIGN_STYLE = Automatic; 301 | DEVELOPMENT_ASSET_PATHS = "\"SwiftUIAppWithCoreData/Preview Content\""; 302 | DEVELOPMENT_TEAM = VX9NFCQJLB; 303 | ENABLE_PREVIEWS = YES; 304 | INFOPLIST_FILE = SwiftUIAppWithCoreData/Info.plist; 305 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 306 | LD_RUNPATH_SEARCH_PATHS = ( 307 | "$(inherited)", 308 | "@executable_path/Frameworks", 309 | ); 310 | PRODUCT_BUNDLE_IDENTIFIER = de.bmaciag.SwiftUIAppWithCoreData; 311 | PRODUCT_NAME = "$(TARGET_NAME)"; 312 | SWIFT_VERSION = 5.0; 313 | TARGETED_DEVICE_FAMILY = "1,2"; 314 | }; 315 | name = Release; 316 | }; 317 | /* End XCBuildConfiguration section */ 318 | 319 | /* Begin XCConfigurationList section */ 320 | 4311855324AF489900167670 /* Build configuration list for PBXProject "SwiftUIAppWithCoreData" */ = { 321 | isa = XCConfigurationList; 322 | buildConfigurations = ( 323 | 4311856524AF489A00167670 /* Debug */, 324 | 4311856624AF489A00167670 /* Release */, 325 | ); 326 | defaultConfigurationIsVisible = 0; 327 | defaultConfigurationName = Release; 328 | }; 329 | 4311856724AF489A00167670 /* Build configuration list for PBXNativeTarget "SwiftUIAppWithCoreData" */ = { 330 | isa = XCConfigurationList; 331 | buildConfigurations = ( 332 | 4311856824AF489A00167670 /* Debug */, 333 | 4311856924AF489A00167670 /* Release */, 334 | ); 335 | defaultConfigurationIsVisible = 0; 336 | defaultConfigurationName = Release; 337 | }; 338 | /* End XCConfigurationList section */ 339 | 340 | /* Begin XCVersionGroup section */ 341 | 4311856A24AF4CF200167670 /* MyModel.xcdatamodeld */ = { 342 | isa = XCVersionGroup; 343 | children = ( 344 | 4311856B24AF4CF200167670 /* MyModel.xcdatamodel */, 345 | ); 346 | currentVersion = 4311856B24AF4CF200167670 /* MyModel.xcdatamodel */; 347 | path = MyModel.xcdatamodeld; 348 | sourceTree = ""; 349 | versionGroupType = wrapper.xcdatamodel; 350 | }; 351 | /* End XCVersionGroup section */ 352 | }; 353 | rootObject = 4311855024AF489900167670 /* Project object */; 354 | } 355 | -------------------------------------------------------------------------------- /SwiftUIAppWithCoreData.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SwiftUIAppWithCoreData.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SwiftUIAppWithCoreData.xcodeproj/xcuserdata/barm.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | SwiftUIAppWithCoreData.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /SwiftUIAppWithCoreData/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /SwiftUIAppWithCoreData/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /SwiftUIAppWithCoreData/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /SwiftUIAppWithCoreData/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // SwiftUIAppWithCoreData 4 | // 5 | // Created by Bartholomäus Maciag on 03.07.20. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct ContentView: View { 11 | @Environment(\.managedObjectContext) var moc 12 | @FetchRequest( 13 | entity: SampleEntity.entity(), 14 | sortDescriptors: [ 15 | NSSortDescriptor(keyPath: \SampleEntity.name, ascending: false) 16 | ] 17 | ) var entities: FetchedResults 18 | 19 | var body: some View { 20 | VStack { 21 | Text("Hello, world!").padding() 22 | 23 | Button(action: { 24 | let newEntry = SampleEntity(context: self.moc) 25 | newEntry.name = "New name" 26 | 27 | if self.moc.hasChanges { 28 | try? self.moc.save() 29 | } 30 | }) { 31 | Text("Add entry") 32 | } 33 | 34 | List(entities, id: \.self) { entity in 35 | Text(entity.name ?? "Unknown") 36 | } 37 | } 38 | } 39 | } 40 | 41 | struct ContentView_Previews: PreviewProvider { 42 | static var previews: some View { 43 | ContentView() 44 | .environment(\.managedObjectContext, PersistentCloudKitContainer.persistentContainer.viewContext) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /SwiftUIAppWithCoreData/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 | 28 | UIApplicationSupportsIndirectInputEvents 29 | 30 | UILaunchScreen 31 | 32 | UIRequiredDeviceCapabilities 33 | 34 | armv7 35 | 36 | UISupportedInterfaceOrientations 37 | 38 | UIInterfaceOrientationPortrait 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UISupportedInterfaceOrientations~ipad 43 | 44 | UIInterfaceOrientationPortrait 45 | UIInterfaceOrientationPortraitUpsideDown 46 | UIInterfaceOrientationLandscapeLeft 47 | UIInterfaceOrientationLandscapeRight 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /SwiftUIAppWithCoreData/MyModel.xcdatamodeld/MyModel.xcdatamodel/contents: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SwiftUIAppWithCoreData/PersistentCloudKitContainer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PersistentCloudKitContainer.swift 3 | // SwiftUIAppWithCoreData 4 | // 5 | // Created by Bartholomäus Maciag on 05.07.20. 6 | // 7 | 8 | import CoreData 9 | public class PersistentCloudKitContainer { 10 | 11 | // MARK: - Define Constants / Variables 12 | public static var context: NSManagedObjectContext { 13 | return persistentContainer.viewContext 14 | } 15 | 16 | // MARK: - Initializer 17 | private init() {} 18 | 19 | // MARK: - Core Data stack 20 | public static var persistentContainer: NSPersistentContainer = { 21 | let container = NSPersistentContainer(name: "MyModel") 22 | container.loadPersistentStores(completionHandler: { (storeDescription, error) in 23 | if let error = error as NSError? { 24 | fatalError("Unresolved error \(error), \(error.userInfo)") 25 | } 26 | }) 27 | // container.viewContext.automaticallyMergesChangesFromParent = true 28 | // container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy 29 | return container 30 | }() 31 | 32 | // MARK: - Core Data Saving support 33 | public static func saveContext () { 34 | let context = persistentContainer.viewContext 35 | if context.hasChanges { 36 | do { 37 | try context.save() 38 | } catch { 39 | let nserror = error as NSError 40 | fatalError("Unresolved error \(nserror), \(nserror.userInfo)") 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /SwiftUIAppWithCoreData/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /SwiftUIAppWithCoreData/SwiftUIAppWithCoreDataApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftUIAppWithCoreDataApp.swift 3 | // SwiftUIAppWithCoreData 4 | // 5 | // Created by Bartholomäus Maciag on 03.07.20. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @main 11 | struct SwiftUIAppWithCoreDataApp: App { 12 | let context = PersistentCloudKitContainer.persistentContainer.viewContext 13 | 14 | var body: some Scene { 15 | WindowGroup { 16 | ContentView().environment(\.managedObjectContext, context) 17 | } 18 | } 19 | } 20 | --------------------------------------------------------------------------------