我有一个我刚刚创建的字符串的 plist 文件;它看起来像这样:
这是我用来创建文件路径的代码:
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); // Create a list of paths
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get a path to your documents directory from the list
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"NailServices.plist"]; // Create a full file path
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath: path]) { // Check if file exists
// Get a path to the plist created before in bundle directory (by Xcode)
NSString *bundle = [[NSBundle mainBundle] pathForResource: @"NailServices" ofType: @"plist"];
[fileManager copyItemAtPath:bundle toPath: path error:&error]; // Copy this plist to your documents directory
}
这是我用来检查数据的代码(以确保它正常工作)......我从 NSLog 语句中得到一个(null)返回)
//Load Dictionary with wood name cross refference values for image name
NSString *plistDataPath = [[NSBundle mainBundle] pathForResource:@"NailServices" ofType:@"plist"];
NSDictionary *NailServicesDictionary = [[NSDictionary alloc] initWithContentsOfFile:plistDataPath];
NSLog(@"\nnailServicesDict: %@", NailServicesDictionary);
这是我第一次尝试创建/使用“字符串”plist 文件;我已经阅读了我在 Google 和 SO 上可以找到的所有内容,但没有找到一个普通的 ol' 字符串文件的示例。我还需要做什么才能获得这个 plist 数据?