我有一個plist文件,我剛剛創建了字符串;它看起來像這樣:爲什麼我不能檢索我的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的語句)
//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數據?
那麼首先,你的plist文件是一個數組,而不是一個字典。嘗試將'NSDictionary'更改爲'NSArray'。 – Jsdodgers
RATS!這是在以下情況下會發生的情況:a)您複製代碼和b)我沒有注意,因爲它是午睡時間!非常感謝你......我現在不在這條路上......:D 請您將您的評論更改爲答案,以便我可以接受它嗎? – SpokaneDude
好的,我把它作爲一個答案加了一點解釋。 – Jsdodgers