ios - Xcode Command Line tools to convert sqlite to coredata returning with nill data -
i trying use command line tools convert sqlite coredata .the problem core data file created nil data .the data in sqlite not copied coredata . followed http://www.raywenderlich.com/12170/core-data-tutorial-how-to-preloadimport-existing-data-updated tutorial .
i created project in osx command line tools added datamodel .xcdatamodel file , entity files project later added mydata.sqlite file in project->targets->buildphases->copyfiles.
my main.m
static nsmanagedobjectmodel *managedobjectmodel() { static nsmanagedobjectmodel *model = nil; if (model != nil) { return model; } nsstring *path = @"mydatamodel"; nsurl *modelurl = [nsurl fileurlwithpath:[path stringbyappendingpathextension:@"mom"]]; model = [[nsmanagedobjectmodel alloc] initwithcontentsofurl:modelurl]; return model; } static nsmanagedobjectcontext *managedobjectcontext() { static nsmanagedobjectcontext *context = nil; if (context != nil) { return context; } @autoreleasepool { context = [[nsmanagedobjectcontext alloc] init]; nspersistentstorecoordinator *coordinator = [[nspersistentstorecoordinator alloc] initwithmanagedobjectmodel:managedobjectmodel()]; [context setpersistentstorecoordinator:coordinator]; nsstring *store_type = nssqlitestoretype; nsstring *path = [[nsprocessinfo processinfo] arguments][0]; path = [path stringbydeletingpathextension]; nsurl *url = [nsurl fileurlwithpath:[path stringbyappendingpathextension:@"sqlite"]]; nserror *error; //note nssqlitepragmasoption nsdictionary *options = @{ nssqlitepragmasoption : @{@"journal_mode" : @"delete"} }; nspersistentstore *newstore = [coordinator addpersistentstorewithtype:store_type configuration:nil url:url options:options error:&error]; if (newstore == nil) { nslog(@"store configuration failure %@", ([error localizeddescription] != nil) ? [error localizeddescription] : @"unknown error"); } } return context; } int main(int argc, const char * argv[]) { @autoreleasepool { // create managed object context nsmanagedobjectcontext *context = managedobjectcontext(); // custom code here... // save managed object context nserror *error = nil; if (![context save:&error]) { nslog(@"error while saving %@", ([error localizeddescription] != nil) ? [error localizeddescription] : @"unknown error"); exit(1); } } } the sqlite converted coredata data mapping not done.the coredata file created nill data .can 1 me issue . thank
Comments
Post a Comment