蜗牛爱课- iOS中plist的创建,数据写入与读取

iOS中plist的创建,数据写入与读取功能创建一个test.plist文件
-(void)triggerStorage
{
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths    objectAtIndex:0];  
    NSString *filename=[path stringByAppendingPathComponent:@"test.plist"];   //获取路径
    NSDictionary* dic2 = [NSDictionary dictionaryWithContentsOfFile:filename];  //读取数据
   NSLog(@"dic2 is:%@",dic2); 
 
   //创建一个dic,写到plist文件里
    NSDictionary* dic = [NSDictionary dictionaryWithObjectsAndKeys:displayLabel.text,@"IP",nil]; //写入数据
    [dic writeToFile:filename atomically:YES];   



    //读文件
    NSDictionary* dic2 = [NSDictionary dictionaryWithContentsOfFile:filename];
    NSLog(@"dic is:%@",dic2);
}

版权声明:欢迎转载,请注明出处:蜗牛爱课 • 移动互联网

posted @ 2016-01-27 15:51  北狐  阅读(223)  评论(0编辑  收藏  举报