CoreData: error: (14) I/O error for database

后端 未结 2 686
醉梦人生
醉梦人生 2021-01-02 11:17

When compiling and running in the XCode a project using Core Data I\'m getting an error I never saw before:

 2013-09-12 16:59:10.156 myapp[57811         


        
2条回答
  •  时光说笑
    2021-01-02 12:16

    NSURL *storeURL = [[NSBundle mainBundle] 
                         URLForResource:@"database" withExtension:@"sqlite"];
    

    builds a path inside the application bundle, which is read-only. The persistent store file needs to reside in a writable directory, e.g. the "Documents" directory.

    EDIT: The above answer is actually wrong, it is possible to open a read-only Core Data file from the application bundle (using NSReadOnlyPersistentStoreOption). The only thing I can currently imagine is that the bundled file is not a valid Core Data database. Adding the launch argument

    -com.apple.CoreData.SQLDebug 1
    

    might help to localize the problem.

提交回复
热议问题