创建plist并写入

 
 1. 创建一个plist文件
 
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);  
    NSString *path=[paths    objectAtIndex:0];
    NSLog(@"path = %@",path);
    NSString *filename=[path stringByAppendingPathComponent:@"test.plist"];    //文件的完整路径
 
    NSFileManager* fm = [NSFileManager defaultManager];
    [fm createFileAtPath:filename contents:nil attributes:nil];      //根据完整路径创建文件  
 
    
2. 创建一个dic,写到plist文件里
    NSDictionary* dic = [NSDictionary dictionaryWithObjectsAndKeys:@"sina",@"1",@"163",@"2",nil];
    [dic writeToFile:filename atomically:YES];
    
3. 读文件内容
    NSDictionary* dic2 = [NSDictionary dictionaryWithContentsOfFile:filename];
    NSLog(@"dic is:%@",dic2);
原文地址:https://www.cnblogs.com/liuziyu/p/4544592.html