└── Core Data ├── Core Data.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── pulkit.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── pulkit.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── Core Data.xcscheme │ └── xcschememanagement.plist └── Core Data ├── AppDelegate.swift ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Core_Data.xcdatamodeld ├── .xccurrentversion └── Core_Data.xcdatamodel │ └── contents ├── Info.plist └── ViewController.swift /Core Data/Core Data.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 02AA90E51F00F3F00016DD4E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02AA90E41F00F3F00016DD4E /* AppDelegate.swift */; }; 11 | 02AA90E71F00F3F00016DD4E /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02AA90E61F00F3F00016DD4E /* ViewController.swift */; }; 12 | 02AA90EA1F00F3F00016DD4E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 02AA90E81F00F3F00016DD4E /* Main.storyboard */; }; 13 | 02AA90ED1F00F3F00016DD4E /* Core_Data.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 02AA90EB1F00F3F00016DD4E /* Core_Data.xcdatamodeld */; }; 14 | 02AA90EF1F00F3F00016DD4E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 02AA90EE1F00F3F00016DD4E /* Assets.xcassets */; }; 15 | 02AA90F21F00F3F00016DD4E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 02AA90F01F00F3F00016DD4E /* LaunchScreen.storyboard */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 02AA90E11F00F3F00016DD4E /* Core Data.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Core Data.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | 02AA90E41F00F3F00016DD4E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 21 | 02AA90E61F00F3F00016DD4E /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 22 | 02AA90E91F00F3F00016DD4E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 23 | 02AA90EC1F00F3F00016DD4E /* Core_Data.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Core_Data.xcdatamodel; sourceTree = ""; }; 24 | 02AA90EE1F00F3F00016DD4E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 25 | 02AA90F11F00F3F00016DD4E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 26 | 02AA90F31F00F3F00016DD4E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | 02AA90DE1F00F3F00016DD4E /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | 02AA90D81F00F3F00016DD4E = { 41 | isa = PBXGroup; 42 | children = ( 43 | 02AA90E31F00F3F00016DD4E /* Core Data */, 44 | 02AA90E21F00F3F00016DD4E /* Products */, 45 | ); 46 | sourceTree = ""; 47 | }; 48 | 02AA90E21F00F3F00016DD4E /* Products */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | 02AA90E11F00F3F00016DD4E /* Core Data.app */, 52 | ); 53 | name = Products; 54 | sourceTree = ""; 55 | }; 56 | 02AA90E31F00F3F00016DD4E /* Core Data */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | 02AA90E41F00F3F00016DD4E /* AppDelegate.swift */, 60 | 02AA90E61F00F3F00016DD4E /* ViewController.swift */, 61 | 02AA90E81F00F3F00016DD4E /* Main.storyboard */, 62 | 02AA90EE1F00F3F00016DD4E /* Assets.xcassets */, 63 | 02AA90F01F00F3F00016DD4E /* LaunchScreen.storyboard */, 64 | 02AA90F31F00F3F00016DD4E /* Info.plist */, 65 | 02AA90EB1F00F3F00016DD4E /* Core_Data.xcdatamodeld */, 66 | ); 67 | path = "Core Data"; 68 | sourceTree = ""; 69 | }; 70 | /* End PBXGroup section */ 71 | 72 | /* Begin PBXNativeTarget section */ 73 | 02AA90E01F00F3F00016DD4E /* Core Data */ = { 74 | isa = PBXNativeTarget; 75 | buildConfigurationList = 02AA90F61F00F3F00016DD4E /* Build configuration list for PBXNativeTarget "Core Data" */; 76 | buildPhases = ( 77 | 02AA90DD1F00F3F00016DD4E /* Sources */, 78 | 02AA90DE1F00F3F00016DD4E /* Frameworks */, 79 | 02AA90DF1F00F3F00016DD4E /* Resources */, 80 | ); 81 | buildRules = ( 82 | ); 83 | dependencies = ( 84 | ); 85 | name = "Core Data"; 86 | productName = "Core Data"; 87 | productReference = 02AA90E11F00F3F00016DD4E /* Core Data.app */; 88 | productType = "com.apple.product-type.application"; 89 | }; 90 | /* End PBXNativeTarget section */ 91 | 92 | /* Begin PBXProject section */ 93 | 02AA90D91F00F3F00016DD4E /* Project object */ = { 94 | isa = PBXProject; 95 | attributes = { 96 | LastSwiftUpdateCheck = 0830; 97 | LastUpgradeCheck = 0830; 98 | ORGANIZATIONNAME = Pulkeet; 99 | TargetAttributes = { 100 | 02AA90E01F00F3F00016DD4E = { 101 | CreatedOnToolsVersion = 8.3.1; 102 | ProvisioningStyle = Automatic; 103 | }; 104 | }; 105 | }; 106 | buildConfigurationList = 02AA90DC1F00F3F00016DD4E /* Build configuration list for PBXProject "Core Data" */; 107 | compatibilityVersion = "Xcode 3.2"; 108 | developmentRegion = English; 109 | hasScannedForEncodings = 0; 110 | knownRegions = ( 111 | en, 112 | Base, 113 | ); 114 | mainGroup = 02AA90D81F00F3F00016DD4E; 115 | productRefGroup = 02AA90E21F00F3F00016DD4E /* Products */; 116 | projectDirPath = ""; 117 | projectRoot = ""; 118 | targets = ( 119 | 02AA90E01F00F3F00016DD4E /* Core Data */, 120 | ); 121 | }; 122 | /* End PBXProject section */ 123 | 124 | /* Begin PBXResourcesBuildPhase section */ 125 | 02AA90DF1F00F3F00016DD4E /* Resources */ = { 126 | isa = PBXResourcesBuildPhase; 127 | buildActionMask = 2147483647; 128 | files = ( 129 | 02AA90F21F00F3F00016DD4E /* LaunchScreen.storyboard in Resources */, 130 | 02AA90EF1F00F3F00016DD4E /* Assets.xcassets in Resources */, 131 | 02AA90EA1F00F3F00016DD4E /* Main.storyboard in Resources */, 132 | ); 133 | runOnlyForDeploymentPostprocessing = 0; 134 | }; 135 | /* End PBXResourcesBuildPhase section */ 136 | 137 | /* Begin PBXSourcesBuildPhase section */ 138 | 02AA90DD1F00F3F00016DD4E /* Sources */ = { 139 | isa = PBXSourcesBuildPhase; 140 | buildActionMask = 2147483647; 141 | files = ( 142 | 02AA90E71F00F3F00016DD4E /* ViewController.swift in Sources */, 143 | 02AA90E51F00F3F00016DD4E /* AppDelegate.swift in Sources */, 144 | 02AA90ED1F00F3F00016DD4E /* Core_Data.xcdatamodeld in Sources */, 145 | ); 146 | runOnlyForDeploymentPostprocessing = 0; 147 | }; 148 | /* End PBXSourcesBuildPhase section */ 149 | 150 | /* Begin PBXVariantGroup section */ 151 | 02AA90E81F00F3F00016DD4E /* Main.storyboard */ = { 152 | isa = PBXVariantGroup; 153 | children = ( 154 | 02AA90E91F00F3F00016DD4E /* Base */, 155 | ); 156 | name = Main.storyboard; 157 | sourceTree = ""; 158 | }; 159 | 02AA90F01F00F3F00016DD4E /* LaunchScreen.storyboard */ = { 160 | isa = PBXVariantGroup; 161 | children = ( 162 | 02AA90F11F00F3F00016DD4E /* Base */, 163 | ); 164 | name = LaunchScreen.storyboard; 165 | sourceTree = ""; 166 | }; 167 | /* End PBXVariantGroup section */ 168 | 169 | /* Begin XCBuildConfiguration section */ 170 | 02AA90F41F00F3F00016DD4E /* Debug */ = { 171 | isa = XCBuildConfiguration; 172 | buildSettings = { 173 | ALWAYS_SEARCH_USER_PATHS = NO; 174 | CLANG_ANALYZER_NONNULL = YES; 175 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 176 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 177 | CLANG_CXX_LIBRARY = "libc++"; 178 | CLANG_ENABLE_MODULES = YES; 179 | CLANG_ENABLE_OBJC_ARC = YES; 180 | CLANG_WARN_BOOL_CONVERSION = YES; 181 | CLANG_WARN_CONSTANT_CONVERSION = YES; 182 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 183 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 184 | CLANG_WARN_EMPTY_BODY = YES; 185 | CLANG_WARN_ENUM_CONVERSION = YES; 186 | CLANG_WARN_INFINITE_RECURSION = YES; 187 | CLANG_WARN_INT_CONVERSION = YES; 188 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 189 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 190 | CLANG_WARN_UNREACHABLE_CODE = YES; 191 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 192 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 193 | COPY_PHASE_STRIP = NO; 194 | DEBUG_INFORMATION_FORMAT = dwarf; 195 | ENABLE_STRICT_OBJC_MSGSEND = YES; 196 | ENABLE_TESTABILITY = YES; 197 | GCC_C_LANGUAGE_STANDARD = gnu99; 198 | GCC_DYNAMIC_NO_PIC = NO; 199 | GCC_NO_COMMON_BLOCKS = YES; 200 | GCC_OPTIMIZATION_LEVEL = 0; 201 | GCC_PREPROCESSOR_DEFINITIONS = ( 202 | "DEBUG=1", 203 | "$(inherited)", 204 | ); 205 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 206 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 207 | GCC_WARN_UNDECLARED_SELECTOR = YES; 208 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 209 | GCC_WARN_UNUSED_FUNCTION = YES; 210 | GCC_WARN_UNUSED_VARIABLE = YES; 211 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 212 | MTL_ENABLE_DEBUG_INFO = YES; 213 | ONLY_ACTIVE_ARCH = YES; 214 | SDKROOT = iphoneos; 215 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 216 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 217 | TARGETED_DEVICE_FAMILY = "1,2"; 218 | }; 219 | name = Debug; 220 | }; 221 | 02AA90F51F00F3F00016DD4E /* Release */ = { 222 | isa = XCBuildConfiguration; 223 | buildSettings = { 224 | ALWAYS_SEARCH_USER_PATHS = NO; 225 | CLANG_ANALYZER_NONNULL = YES; 226 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 227 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 228 | CLANG_CXX_LIBRARY = "libc++"; 229 | CLANG_ENABLE_MODULES = YES; 230 | CLANG_ENABLE_OBJC_ARC = YES; 231 | CLANG_WARN_BOOL_CONVERSION = YES; 232 | CLANG_WARN_CONSTANT_CONVERSION = YES; 233 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 234 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 235 | CLANG_WARN_EMPTY_BODY = YES; 236 | CLANG_WARN_ENUM_CONVERSION = YES; 237 | CLANG_WARN_INFINITE_RECURSION = YES; 238 | CLANG_WARN_INT_CONVERSION = YES; 239 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 240 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 241 | CLANG_WARN_UNREACHABLE_CODE = YES; 242 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 243 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 244 | COPY_PHASE_STRIP = NO; 245 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 246 | ENABLE_NS_ASSERTIONS = NO; 247 | ENABLE_STRICT_OBJC_MSGSEND = YES; 248 | GCC_C_LANGUAGE_STANDARD = gnu99; 249 | GCC_NO_COMMON_BLOCKS = YES; 250 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 251 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 252 | GCC_WARN_UNDECLARED_SELECTOR = YES; 253 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 254 | GCC_WARN_UNUSED_FUNCTION = YES; 255 | GCC_WARN_UNUSED_VARIABLE = YES; 256 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 257 | MTL_ENABLE_DEBUG_INFO = NO; 258 | SDKROOT = iphoneos; 259 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 260 | TARGETED_DEVICE_FAMILY = "1,2"; 261 | VALIDATE_PRODUCT = YES; 262 | }; 263 | name = Release; 264 | }; 265 | 02AA90F71F00F3F00016DD4E /* Debug */ = { 266 | isa = XCBuildConfiguration; 267 | buildSettings = { 268 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 269 | INFOPLIST_FILE = "Core Data/Info.plist"; 270 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 271 | PRODUCT_BUNDLE_IDENTIFIER = "com.something.something.Core-Data"; 272 | PRODUCT_NAME = "$(TARGET_NAME)"; 273 | SWIFT_VERSION = 3.0; 274 | }; 275 | name = Debug; 276 | }; 277 | 02AA90F81F00F3F00016DD4E /* Release */ = { 278 | isa = XCBuildConfiguration; 279 | buildSettings = { 280 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 281 | INFOPLIST_FILE = "Core Data/Info.plist"; 282 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 283 | PRODUCT_BUNDLE_IDENTIFIER = "com.something.something.Core-Data"; 284 | PRODUCT_NAME = "$(TARGET_NAME)"; 285 | SWIFT_VERSION = 3.0; 286 | }; 287 | name = Release; 288 | }; 289 | /* End XCBuildConfiguration section */ 290 | 291 | /* Begin XCConfigurationList section */ 292 | 02AA90DC1F00F3F00016DD4E /* Build configuration list for PBXProject "Core Data" */ = { 293 | isa = XCConfigurationList; 294 | buildConfigurations = ( 295 | 02AA90F41F00F3F00016DD4E /* Debug */, 296 | 02AA90F51F00F3F00016DD4E /* Release */, 297 | ); 298 | defaultConfigurationIsVisible = 0; 299 | defaultConfigurationName = Release; 300 | }; 301 | 02AA90F61F00F3F00016DD4E /* Build configuration list for PBXNativeTarget "Core Data" */ = { 302 | isa = XCConfigurationList; 303 | buildConfigurations = ( 304 | 02AA90F71F00F3F00016DD4E /* Debug */, 305 | 02AA90F81F00F3F00016DD4E /* Release */, 306 | ); 307 | defaultConfigurationIsVisible = 0; 308 | }; 309 | /* End XCConfigurationList section */ 310 | 311 | /* Begin XCVersionGroup section */ 312 | 02AA90EB1F00F3F00016DD4E /* Core_Data.xcdatamodeld */ = { 313 | isa = XCVersionGroup; 314 | children = ( 315 | 02AA90EC1F00F3F00016DD4E /* Core_Data.xcdatamodel */, 316 | ); 317 | currentVersion = 02AA90EC1F00F3F00016DD4E /* Core_Data.xcdatamodel */; 318 | path = Core_Data.xcdatamodeld; 319 | sourceTree = ""; 320 | versionGroupType = wrapper.xcdatamodel; 321 | }; 322 | /* End XCVersionGroup section */ 323 | }; 324 | rootObject = 02AA90D91F00F3F00016DD4E /* Project object */; 325 | } 326 | -------------------------------------------------------------------------------- /Core Data/Core Data.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Core Data/Core Data.xcodeproj/project.xcworkspace/xcuserdata/pulkit.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vorapulkit/CoreData/7c9f9c8bdfb3c2bc355332284cf522f2f49afcb8/Core Data/Core Data.xcodeproj/project.xcworkspace/xcuserdata/pulkit.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Core Data/Core Data.xcodeproj/xcuserdata/pulkit.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 20 | 21 | 22 | 24 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Core Data/Core Data.xcodeproj/xcuserdata/pulkit.xcuserdatad/xcschemes/Core Data.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Core Data/Core Data.xcodeproj/xcuserdata/pulkit.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Core Data.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 02AA90E01F00F3F00016DD4E 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Core Data/Core Data/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Core Data 4 | // 5 | // Created by Pulkit on 6/26/17. 6 | // Copyright © 2017 Pulkeet. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import CoreData 11 | 12 | @UIApplicationMain 13 | class AppDelegate: UIResponder, UIApplicationDelegate { 14 | 15 | var window: UIWindow? 16 | 17 | 18 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 19 | // Override point for customization after application launch. 20 | 21 | 22 | 23 | getRecordFromCoreData() 24 | return true 25 | } 26 | 27 | func applicationWillResignActive(_ application: UIApplication) { 28 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 29 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics 30 | } 31 | 32 | func applicationDidEnterBackground(_ application: UIApplication) { 33 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 34 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 35 | } 36 | 37 | func applicationWillEnterForeground(_ application: UIApplication) { 38 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 39 | } 40 | 41 | func applicationDidBecomeActive(_ application: UIApplication) { 42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 43 | } 44 | 45 | func applicationWillTerminate(_ application: UIApplication) { 46 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 47 | // Saves changes in the application's managed object context before the application terminates. 48 | self.saveContext() 49 | } 50 | 51 | // MARK: - Core Data stack 52 | 53 | lazy var persistentContainer: NSPersistentContainer = { 54 | /* 55 | The persistent container for the application. This implementation 56 | creates and returns a container, having loaded the store for the 57 | application to it. This property is optional since there are legitimate 58 | error conditions that could cause the creation of the store to fail. 59 | */ 60 | let container = NSPersistentContainer(name: "Core_Data") 61 | container.loadPersistentStores(completionHandler: { (storeDescription, error) in 62 | if let error = error as NSError? { 63 | // Replace this implementation with code to handle the error appropriately. 64 | // fatalError() 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. 65 | 66 | /* 67 | Typical reasons for an error here include: 68 | * The parent directory does not exist, cannot be created, or disallows writing. 69 | * The persistent store is not accessible, due to permissions or data protection when the device is locked. 70 | * The device is out of space. 71 | * The store could not be migrated to the current model version. 72 | Check the error message to determine what the actual problem was. 73 | */ 74 | fatalError("Unresolved error \(error), \(error.userInfo)") 75 | } 76 | }) 77 | return container 78 | }() 79 | 80 | // MARK: - Core Data Saving support 81 | 82 | func saveContext () { 83 | let context = persistentContainer.viewContext 84 | if context.hasChanges { 85 | do { 86 | try context.save() 87 | } catch { 88 | // Replace this implementation with code to handle the error appropriately. 89 | // fatalError() 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. 90 | let nserror = error as NSError 91 | fatalError("Unresolved error \(nserror), \(nserror.userInfo)") 92 | } 93 | } 94 | } 95 | 96 | lazy var managedObjectModel: NSManagedObjectModel = { 97 | let modelURL = Bundle.main.url(forResource: "Core_Data", withExtension: "momd")! 98 | return NSManagedObjectModel(contentsOf: modelURL)! 99 | }() 100 | 101 | lazy var managedObjectContext: NSManagedObjectContext = { 102 | let coordinator = self.persistentStoreCoordinator 103 | var managedObjectContext = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType) 104 | managedObjectContext.persistentStoreCoordinator = coordinator 105 | return managedObjectContext 106 | }() 107 | 108 | lazy var applicationDocumentsDirectory: NSURL = { 109 | let urls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) 110 | return urls[urls.count-1] as NSURL 111 | }() 112 | 113 | lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator = { 114 | let coordinator = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel) 115 | let url = self.applicationDocumentsDirectory.appendingPathComponent("SingleViewCoreData.sqlite") 116 | var failureReason = "There was an error creating or loading the application's saved data." 117 | do { 118 | try coordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: nil) 119 | } catch { 120 | var dict = [String: AnyObject]() 121 | dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data" as AnyObject 122 | dict[NSLocalizedFailureReasonErrorKey] = failureReason as AnyObject 123 | 124 | dict[NSUnderlyingErrorKey] = error as NSError 125 | let wrappedError = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict) 126 | NSLog("Unresolved error \(wrappedError), \(wrappedError.userInfo)") 127 | abort() 128 | } 129 | 130 | return coordinator 131 | }() 132 | 133 | 134 | //MARK: 135 | //MARK: Get Record 136 | func getRecordFromCoreData(){ 137 | 138 | let result = fetchRecord(strEntity: "Person") 139 | if (result != nil && (result?.count)! > 0) { 140 | let person = result?[0] as! NSManagedObject 141 | 142 | print(person.value(forKey: "fullname") ?? "") 143 | print(person.value(forKey: "lastname") ?? "") 144 | print(person.value(forKey: "name") ?? "") 145 | print(person.value(forKey: "addresses") ?? "") 146 | 147 | 148 | // applyRelationship(coreDataObj: person) 149 | 150 | } 151 | 152 | } 153 | //MARK: 154 | //MARK: Create Managed Object 155 | // Insert Record 156 | func createRecord(){ 157 | 158 | let entityDescription = NSEntityDescription.entity(forEntityName: "Person", in: self.managedObjectContext) 159 | let newPerson = NSManagedObject(entity: entityDescription!, insertInto: self.managedObjectContext) 160 | newPerson.setValue("Ravi Jada Khodabhai", forKey: "fullname") 161 | newPerson.setValue("Jada", forKey: "lastname") 162 | newPerson.setValue("Ravi", forKey: "name") 163 | 164 | 165 | saveRecord(coreDataObj: newPerson) 166 | 167 | } 168 | 169 | //MARK: 170 | //MARK: CoreData Supportive 171 | func fetchRecord(strEntity : String)->[Any]?{ 172 | 173 | // Initialize Fetch Request 174 | let fetchRequest = NSFetchRequest() 175 | 176 | // Create Entity Description 177 | let entityDescription = NSEntityDescription.entity(forEntityName: strEntity, in: self.managedObjectContext) 178 | 179 | // Configure Fetch Request 180 | fetchRequest.entity = entityDescription 181 | 182 | do { 183 | let result = try self.managedObjectContext.fetch(fetchRequest) 184 | print(result) 185 | return result 186 | 187 | } catch { 188 | let fetchError = error as NSError 189 | print(fetchError) 190 | return nil 191 | 192 | } 193 | } 194 | 195 | func saveRecord(coreDataObj: NSManagedObject){ 196 | do { 197 | try coreDataObj.managedObjectContext?.save() 198 | } catch { 199 | print(error.localizedDescription) 200 | } 201 | } 202 | 203 | func deleteRecord(coreDataObj: NSManagedObject){ 204 | self.managedObjectContext.delete(coreDataObj) 205 | 206 | do { 207 | try self.managedObjectContext.save() 208 | } catch { 209 | let saveError = error as NSError 210 | print(saveError) 211 | } 212 | } 213 | 214 | 215 | func applyRelationship(coreDataObj: NSManagedObject){ 216 | 217 | 218 | // Create Address 219 | let entityAddress = NSEntityDescription.entity(forEntityName: "Address", in: self.managedObjectContext) 220 | let newAddress = NSManagedObject(entity: entityAddress!, insertInto: self.managedObjectContext) 221 | 222 | // Populate Address 223 | newAddress.setValue("Main Street", forKey: "street") 224 | newAddress.setValue("Boston", forKey: "city") 225 | 226 | // Add Address to Person 227 | coreDataObj.setValue(NSSet(object: newAddress), forKey: "addresses") 228 | 229 | do { 230 | try coreDataObj.managedObjectContext?.save() 231 | } catch { 232 | let saveError = error as NSError 233 | print(saveError) 234 | } 235 | } 236 | 237 | 238 | } 239 | 240 | -------------------------------------------------------------------------------- /Core Data/Core Data/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | } 88 | ], 89 | "info" : { 90 | "version" : 1, 91 | "author" : "xcode" 92 | } 93 | } -------------------------------------------------------------------------------- /Core Data/Core Data/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Core Data/Core Data/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 | -------------------------------------------------------------------------------- /Core Data/Core Data/Core_Data.xcdatamodeld/.xccurrentversion: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | _XCCurrentVersionName 6 | Core_Data.xcdatamodel 7 | 8 | 9 | -------------------------------------------------------------------------------- /Core Data/Core Data/Core_Data.xcdatamodeld/Core_Data.xcdatamodel/contents: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Core Data/Core Data/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Core Data/Core Data/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Core Data 4 | // 5 | // Created by Pulkit on 6/26/17. 6 | // Copyright © 2017 Pulkeet. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | // Do any additional setup after loading the view, typically from a nib. 16 | } 17 | 18 | override func didReceiveMemoryWarning() { 19 | super.didReceiveMemoryWarning() 20 | // Dispose of any resources that can be recreated. 21 | } 22 | 23 | 24 | } 25 | 26 | --------------------------------------------------------------------------------