向PLIST文件中追加数据

1.先定一个可变数组:
    NSMutableArray  * operateArray;
2.然后在给可变数组中初始化数据,并向其中追加数据.代码如下:
    NSString  *path = [[ NSBundle  mainBundle pathForResource : @"rchd"  ofType : @"plist" ];
     self . operateArray  = [[ NSMutableArray  alloc initWithContentsOfFile :path];
    
     NSString *titleKey= @" 这是测试 ";
     NSString *imageKey= @"315.jpg";
     NSString *stateKey= @"0";
     NSString *timeKey= @"2012-12-24";

     //你可以在初始化的时候指定容纳对象的个数  1表示只容纳 1
    //NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithCapacity:1];
     //这个数组容纳对象个数不定的话则使用 init
    NSMutableDictionary  *dict = [[NSMutableDictionary   alloc ] init ];
    [dict  setValue:titleKey  forKey: @"titleKey"];
    [dict  setValue:imageKey  forKey: @"imageKey"];
    [dict  setValue:stateKey  forKey: @"stateKey"];
    [dict  setValue:timeKey  forKey: @"timeKey"];
    [ self. operateArray  addObject:dict];
    [ self . operateArray   writeToFile :path  atomically : YES ];
    [dict   release];

你可能感兴趣的:(追加,plist)