- NSUserDefaults只能读写Library/Preferences/<Application BundleIdentifier>.plist这个 文件
- PList文件是XML格式的,只能存放固定数据格式的对象
- PList文件支持的数据格式有NSString, NSNumber, Boolean, NSDate, NSData, * NSArray,和NSDictionary。其中,Boolean格式事实上以[NSNumber numberOfBool:YES/NO];这样的形式表示。NSNumber支持float和int两种格式。
1.创建PList文件
_path = [NSTemporaryDirectory()
stringByAppendingString:@"custom.plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];
}
if (![fileManager fileExistsAtPath:_path]) {
//使用NSMutableDictionary的写文件接口自动创建一个
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
dict[@"textField"] = @"hello,world!";
if (![dict writeToFile:_path atomically:YES]) {
NSLog(@"Error!!!");
}
2.写入PList文件
- (IBAction)saveData:(id)sender {
}
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
dict[@"textField"] = _textField.text;
if (![dict writeToFile:_path atomically:YES]) {
NSLog(@"Error!!!");
}
3.读取文件
{
NSMutableDictionary *dict = [NSMutableDictionary
dictionaryWithContentsOfFile:_path];
NSString *content = dict[@"textField"];
if (content && content.length > 0) {
_textField.text = content;
}
}