diff --git a/FailedBankCD.xcodeproj/project.pbxproj b/FailedBankCD.xcodeproj/project.pbxproj index 1fd23eb..7d2207a 100644 --- a/FailedBankCD.xcodeproj/project.pbxproj +++ b/FailedBankCD.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 4B07960D153A96F4002349B8 /* CoreDataTutorial2.sqlite in Resources */ = {isa = PBXBuildFile; fileRef = 4B07960C153A96F4002349B8 /* CoreDataTutorial2.sqlite */; }; 4B7AB8BD151D932E00FB21FA /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B7AB8BC151D932E00FB21FA /* UIKit.framework */; }; 4B7AB8BF151D932E00FB21FA /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B7AB8BE151D932E00FB21FA /* Foundation.framework */; }; 4B7AB8C1151D932E00FB21FA /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B7AB8C0151D932E00FB21FA /* CoreGraphics.framework */; }; @@ -22,6 +23,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 4B07960C153A96F4002349B8 /* CoreDataTutorial2.sqlite */ = {isa = PBXFileReference; lastKnownFileType = file; path = CoreDataTutorial2.sqlite; sourceTree = ""; }; 4B7AB8B8151D932E00FB21FA /* FailedBankCD.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FailedBankCD.app; sourceTree = BUILT_PRODUCTS_DIR; }; 4B7AB8BC151D932E00FB21FA /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 4B7AB8BE151D932E00FB21FA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -89,6 +91,7 @@ 4B7AB8C4151D932E00FB21FA /* FailedBankCD */ = { isa = PBXGroup; children = ( + 4B07960C153A96F4002349B8 /* CoreDataTutorial2.sqlite */, 4B7AB8CD151D932E00FB21FA /* FBCDAppDelegate.h */, 4B7AB8CE151D932E00FB21FA /* FBCDAppDelegate.m */, 4B7AB8D0151D932E00FB21FA /* MainStoryboard.storyboard */, @@ -169,6 +172,7 @@ files = ( 4B7AB8C9151D932E00FB21FA /* InfoPlist.strings in Resources */, 4B7AB8D2151D932E00FB21FA /* MainStoryboard.storyboard in Resources */, + 4B07960D153A96F4002349B8 /* CoreDataTutorial2.sqlite in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/FailedBankCD/CoreDataTutorial2.sqlite b/FailedBankCD/CoreDataTutorial2.sqlite new file mode 100644 index 0000000..0f65b5d Binary files /dev/null and b/FailedBankCD/CoreDataTutorial2.sqlite differ diff --git a/FailedBankCD/FBCDAppDelegate.m b/FailedBankCD/FBCDAppDelegate.m index 87762e2..1c2d132 100644 --- a/FailedBankCD/FBCDAppDelegate.m +++ b/FailedBankCD/FBCDAppDelegate.m @@ -140,6 +140,16 @@ - (NSPersistentStoreCoordinator *)persistentStoreCoordinator } NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"FailedBankCD.sqlite"]; + + if (![[NSFileManager defaultManager] fileExistsAtPath:[storeURL path]]) { + NSURL *preloadURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"CoreDataTutorial2" ofType:@"sqlite"]]; + + NSError* err = nil; + + if (![[NSFileManager defaultManager] copyItemAtURL:preloadURL toURL:storeURL error:&err]) { + NSLog(@"Oops, could copy preloaded data"); + } + } NSError *error = nil; __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];