- (void)viewDidLoad
{
    [super viewDidLoad];
    
    NSDictionary *dictionary1 = [NSDictionary dictionaryWithObjectsAndKeys:@"1",@"a",@"2",@"b", nil];
    NSDictionary *dictionary2 = [NSDictionary dictionaryWithObjectsAndKeys:@"3",@"c",@"4",@"d", nil];
	
    // 获取应用程序沙盒的Documents目录
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *plistPath = [paths objectAtIndex:0];
    
    // plist文件完整路径
    NSString *filename=[plistPath stringByAppendingPathComponent:@"test.plist"];
    
    // *写入(原有数据被覆盖)
    [dictionary1 writeToFile:filename atomically:YES];
    [dictionary2 writeToFile:filename atomically:YES];
    
    // *读取
    NSDictionary *dic = [[NSMutableDictionary alloc] initWithContentsOfFile:filename];
    NSLog(@"%@", dic);
}

 


输出结果:
plist文件读写_数据


结论:重复对同一plist写入数据,后一次写入的数据将覆盖前一次写入的数据。


plist文件读写_plist文件_02