#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSString *myFileName=@"file";
NSDictionary *myDic1=[NSDictionary dictionaryWithObjectsAndKeys:@"beijing",@"one",@"shanghai",@"two", nil];
NSDictionary *myDic2=[NSDictionary dictionaryWithObjectsAndKeys:@"wuhan",@"three",@"chongqing",@"four",@"nanjing",@"five", nil];
// 创建可变数组 NSMutableArray 添加的元素是字典
NSMutableArray *myArr=[[NSMutableArray alloc] initWithObjects:myDic1,myDic2, nil];
//将数组写入文件
[myArr writeToFile:myFileName atomically:YES];
//从文件中读取
NSMutableArray *myArray=[NSMutableArray arrayWithContentsOfFile:myFileName];
NSLog(@"%i:%@",1,[myArray objectAtIndex:1]);//输出第二个字典
//输出所有的字典
OC 将字典写入数组 并将数组写入文件 对文件内容操作
最新推荐文章于 2021-05-22 19:39:23 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)