简体   繁体   中英

Why this line isn't going to work on real iOS device?

In iOS development when using Core Data framework, why this line wont work in real device:

NSURL *storeUrl = [NSURL fileURLWithPath: 
                  [[self applicationDocumentsDirectory] 
                       stringByAppendingPathComponent: @”MyDB.sqlite”]];

Doesn't this mean that the DB file is under UUID/Documents directory? or it means it is under UUDI/MyApp.app/Documents?

applicationDocumentsDirectory should be pointing to GUID/YourApp/Documents

This would be a correct usage to get the Documents directory

+(NSString *)applicationDocumentsDirectory {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
    return basePath;
}

What is the applicationDocumentsDirectory code? Assuming you are using it from an example, either from Apple or another reliable source, this should point to your apps Documents folder.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM