Core data to existing project issue
I am migrating a core data using sqlite as the persistentStoreCoordinator, the Core Data Model, entities, I created everything, but now my problem is I don't know how to make Core Data to write initial data file to the file I put in the mainBunddle. And there is always error like this:
-[NSKeyedUnarchiver initForReadingWithData:]: data is empty; did you forget to send -finishEncoding to the NSKeyedArchiver?
2011-07-14 17:37:59.409 SalePersonApp[1202:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableArray insertObject:atIndex:]: attempt to insert nil object at 0'
when I assign my context to the appDelegate Context:
开发者_开发百科SalePersonAppAppDelegate *app = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = app.managedObjectContext;
Error was at the second line.
Right now my sqlite files are empty because as I told, I don't know how to make the Core Data write back my Entities to the sql file.
Can anyone tell me how to do this. Thanks so much in advance.
If you put your persistent store inside the application bundle, then it is permanently readonly because everything inside the app bundle is read only.
To make a writable store, you need to create the store in one of the app directories outside the bundle usually either in Documents
or Library
.
If you need to provide a pre-populated persistent store, use Core Data to populate the store when run within Xcode. Then add the persistent store file itself to the build target so that it will be written into the app bundle. The first time the app runs, copy the persistent store from the app bundle to one of the writable directories. Then open the copy as normal.
精彩评论