下面是我的方法來保存數據:無法保存數據到PList
self.doctorString = @"Doctor Bob";
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"doctorprofile.plist"];
NSDictionary *plistDict = [[NSDictionary alloc] initWithObjects: [NSArray arrayWithObjects: self.doctorString, nil] forKeys:[NSArray arrayWithObjects: @"DoctorName", nil]];
NSError *error = nil;
NSData *plistData = [NSPropertyListSerialization dataWithPropertyList:plistDict format:NSPropertyListXMLFormat_v1_0 options:0 error:&error];
if(plistData){
[plistDict writeToFile:plistPath atomically:YES];
NSLog(@"Data saved successfully");
NSLog(@"Error : %@",error);
}else{
NSLog(@"Data not happily saved");
}
我的plist結構如下: -
它返回Data saved successfully
消息,但是當我在檢查plist文件,它不會保存在那裏。
對'writeToFile:'調用的返回值是什麼? – rmaddy
@rmaddy通向doctorprofile.plist – user1498840
的路徑。不是'YES'或'NO'。檢查'writeToFile:'的返回值。 – rmaddy