这很简单。但是您可能想改为查看 NSMutableDictionary。NSString 和 Dictionary 都有 writeToFile:@"filename.txt" 方法。
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:[nameField stringValue] forKey:@"name"];
[dict setValue:[weightField stringValue] forKey:@"weight"];
[dict setValue:date forKey:@"date"];
[dict writeToFile:name atomically:YES];
你以同样的方式从文件中读取,
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:name];
尽可能简单