iPhone Core Data does not fetch any data from Sqlite3 -


i copied filled, existing sqlite3-file project; found (i check with

- (void)createeditablecopyofdatabaseifneeded {     nslog(@"checking if have create editable copy of database");      // first, test existence.     bool success;     nsfilemanager *filemanager = [nsfilemanager defaultmanager];     nserror *error;     nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);     nsstring *documentsdirectory = [paths objectatindex:0];     nsstring *writabledbpath = [documentsdirectory stringbyappendingpathcomponent:@"hvw.sqlite"];     success = [filemanager fileexistsatpath:writabledbpath];     if (success) return;     nslog(@"creating editable copy of database");     // writable database not exist, copy default appropriate location.     nsstring *defaultdbpath = [[[nsbundle mainbundle] resourcepath] stringbyappendingpathcomponent:@"hvw.sqlite"];     success = [filemanager copyitematpath:defaultdbpath topath:writabledbpath error:&error];     if (!success) {         nsassert1(0, @"failed create writable database file message '%@'.", [error localizeddescription]);     } } 

i not come "creating editable copy of database"-part, file there , found.

but fetch not return results:

nsfetchrequest *request = [[nsfetchrequest alloc] init];  nsentitydescription *entity = [nsentitydescription entityforname:@"game" inmanagedobjectcontext:managedobjectcontext];  [request setentity:entity];  nserror *error;  nsmutablearray *mutablefetchresults = [[managedobjectcontext executefetchrequest:request error:&error] mutablecopy]; 

no error thrown, resulting array empty...

edit

i replaced line

nsstring *documentsdirectory = [paths objectatindex:0]; 

by

nsstring *documentsdirectory = [self applicationdocumentsdirectory]; 

and in log file see error while trying save or read objects:

operation not completed. (cocoa error 256.) 

was sqlite database created using core data? can't use sqlite database want persistent store, has have exact internal format core data uses.

if standard sqlite database want bring across core data, recommendation write migration method takes in sqlite , creates core data managed objects that, setting of appropriate relationships. when migration operation has completed, can write out resulting persistent store disk , use core data within application on. if you're more adventurous, can have migration take place on background thread, passing notifications add managed objects main thread's managed object context parsed sqlite.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -