我試圖使用的plist存儲陣列與下面的代碼:問題保存的plist
NSString *name = firstName.text;
NSString *path = [[NSBundle mainBundle] pathForResource:@"Names" ofType:@"plist"];
NSMutableArray *namesArray = [[NSMutableArray alloc] initWithContentsOfFile:path];
[namesArray addObject:name];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
[paths release];
NSString *docDirPath = [documentsDirectory stringByAppendingPathComponent:@"Names.plist"];
[namesArray writeToFile:docDirPath atomically:YES];
namesArray = [[NSMutableArray alloc] initWithContentsOfFile:docDirPath];
此代碼似乎工作。使用NSLog
,我發現在這段代碼執行後,plist包含我想要的內容,但是,我的程序崩潰了,因爲它在設備上生成了一個EXC_BAD_ACCESS
,而在模擬器上它只是崩潰而沒有解釋。有誰知道爲什麼會發生?