plist使用的若干问题

弄了半天的plist,最无语的莫过于plist还分种类的。有字典型和数组型等。

plist的写入是,你把你放在工程中的plist删掉。你要写入plist的时候,
如果发现没有该plist,其会帮新建该plist。别傻傻的认为自己建立一个plist,然后
运行程序的时候他会在你建的那plist里面多出几行数据,因为你修改的是应用中的
plist而非你本地的那个plist。
下面的plist里面存放这的是array数组
以下是显示plist的代码:

NSString *path = [[NSBundle mainBundlepathForResource:@"Data" ofType:@"plist"];

NSMutableArray *array = [[NSMutableArray allocinitWithContentsOfFile:path];

 

 NSLog(@"array:%@",[array objectAtIndex:0]);

写入plist的代码:

 

 NSString *path1 = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];

 NSArray *array1 = [[NSArray alloc] initWithObjects:@"hello1",@"hello2",@"hello3",nil];

 [array1 writeToFile:path1 atomically:YES];

就这么简单。

 

 

  NSString *path = [[NSBundle mainBundlepathForResource:@"Data" ofType:@"plist"];

    NSMutableArray *array = [[NSMutableArray allocinitWithContentsOfFile:path];

    NSString *str=@"第六章——第三阶——第五页";

   [array insertObject:str atIndex:[array count]];    //添加一行:

    [array removeObjectsAtIndexes:2];                   //删除第三行

    [array replaceObjectsAtIndexes:2 withObjects:str;//修改第三行

    [array writeToFile:path atomically:YES];

//[array insertObject:@"hello" atIndex:2];//在第三个数后添加一个hello

//[array removeLastObject];//删掉最后一个

//[array count];         //数组的总数

还有很多函数提供选择:

 

- (void)insertObjects:(NSArray *)objects atIndexes:(NSIndexSet *)indexes;

- (void)removeObjectsAtIndexes:(NSIndexSet *)indexes;

- (void)replaceObjectsAtIndexes:(NSIndexSet *)indexes withObjects:(NSArray *)objects;

- (void)addObject:(id)anObject;

- (void)insertObject:(id)anObject atIndex:(NSUInteger)index;

- (void)removeLastObject;

- (void)removeObjectAtIndex:(NSUInteger)index;

- (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject;

 

- (void)addObjectsFromArray:(NSArray *)otherArray;

- (void)exchangeObjectAtIndex:(NSUInteger)idx1 withObjectAtIndex:(NSUInteger)idx2;

- (void)removeAllObjects;        //清空plist

- (void)removeObject:(id)anObject inRange:(NSRange)range;

- (void)removeObject:(id)anObject;

- (void)removeObjectIdenticalTo:(id)anObject inRange:(NSRange)range;

- (void)removeObjectIdenticalTo:(id)anObject;

- (void)removeObjectsFromIndices:(NSUInteger *)indices numIndices:(NSUInteger)cntNS_DEPRECATED(10_0, 10_6, 2_0, 4_0);

- (void)removeObjectsInArray:(NSArray *)otherArray;

- (void)removeObjectsInRange:(NSRange)range;

- (void)replaceObjectsInRange:(NSRange)range withObjectsFromArray:(NSArray *)otherArray range:(NSRange)otherRange;

- (void)replaceObjectsInRange:(NSRange)range withObjectsFromArray:(NSArray *)otherArray;

- (void)setArray:(NSArray *)otherArray;

- (void)sortUsingFunction:(NSInteger (*)(ididvoid *))compare context:(void *)context;

- (void)sortUsingSelector:(SEL)comparator;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值