importing sqlite to coredata

前端 未结 3 1831
遇见更好的自我
遇见更好的自我 2021-02-11 09:23

I have imported sqlite prepopulated dbs to my coredata projects before, but now I have created a project in the 3.2.5. xcode, wich changes nsurl for nstring in the AppDelegate,

3条回答
  •  广开言路
    2021-02-11 09:34

    apple changed the helper method that returns the application dictionary in the core data templates.

    You are relying on this version:

    - (NSString *)applicationDocumentsDirectory {
        return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    }
    

    but apple changed it to this version

    - (NSURL *)applicationDocumentsDirectory {
        return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
    }
    

    to fix it, just change this.

    NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"ChildCare_v02.sqlite"]; //WARNING !! here
    NSURL *storeUrl = [NSURL fileURLWithPath:storePath]; 
    //NSURL *storeURL = [[self applicationDocumentsDirectory]    URLByAppendingPathComponent:@"ChildCare_v02.sqlite"]; //actual SDK style for blank db
    

    to this

    //NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"ChildCare_v02.sqlite"]; //WARNING !! here
    //NSURL *storeUrl = [NSURL fileURLWithPath:storePath]; 
    NSURL *storeUrl = [[self applicationDocumentsDirectory]    URLByAppendingPathComponent:@"ChildCare_v02.sqlite"]; //actual SDK style for blank db
    

    sorry, but omfg

提交回复
热议问题