数据持久化,常见4种:归档,plist文件,sqlite,coreData.今天复习的是plist文件读写.

//
// ViewController.m
// Test_Plist
//
// Created by lidongbo on 14/10/30.
// Copyright (c) 2014年 lidongbo. All rights reserved.
// #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. /*
读取plist文件的内容.
*/
NSString * path = [[NSBundle mainBundle] pathForResource:@"Person" ofType:@"plist"];
NSMutableDictionary * data = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
NSLog(@"%@",data); /*
获取Document文件夹中plist文件的路径
*/
NSMutableArray * mArr = [[NSMutableArray alloc] initWithObjects:@"英语",@"数据",@"法语",@"日语",@"德语", nil];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * plistPath = [paths objectAtIndex:0];
NSLog(@"%@",plistPath); // NSString * fileName = [plistPath stringByAppendingString:@"/Person.plist"];
NSString * fileName = [plistPath stringByAppendingPathComponent:@"Person.plist"]; /*
赋值
*/
[data setObject:mArr forKey:@"kemu"];
[data setObject:@"14" forKey:@"age"];
/*
plist文件写入
*/
[data writeToFile:fileName atomically:YES]; NSMutableDictionary * data1 = [[NSMutableDictionary alloc] initWithContentsOfFile:fileName];
NSLog(@"%@",data1); /*
plist文件可以多次写入.
*/
NSMutableArray * mmArr = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3", nil];
[data setObject:mmArr forKey:@"kemu"]; [data writeToFile:fileName atomically:YES]; NSMutableDictionary * data2 = [[NSMutableDictionary alloc] initWithContentsOfFile:fileName];
NSLog(@"______%@",data2); } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

数据持久化-Plist文件写入的更多相关文章

  1. 写入数据到Plist文件中时,第一次要创建一个空的数组,否则写入文件失败

    #pragma mark - 保存数据到本地Plist文件中 - (void)saveValidateCountWithDate:(NSString *)date count:(NSString *) ...

  2. IOS开发--数据持久化篇文件存储(二)

    前言:个人觉得开发人员最大的悲哀莫过于懂得使用却不明白其中的原理.在代码之前我觉得还是有必要简单阐述下相关的一些知识点. 因为文章或深或浅总有适合的人群.若有朋友发现了其中不正确的观点还望多多指出,不 ...

  3. python(四)数据持久化操作 文件存储

    1.写入 导入pickle包 然后组织一个列表my_list,保存为pkl格式,可以是任意格式 在磁盘下回出现一个保存的文件 2.读取

  4. Android数据持久化技术 — — —文件存储

    文件保存 package com.example.datastroredtest; import android.app.Activity;import android.os.Bundle;impor ...

  5. iOS开发——数据持久化OC篇&plist文件增删改查操作

    Plist文件增删查改   主要操作: 1.//获得plist路径    -(NSString*)getPlistPath: 2.//判断沙盒中名为plistname的文件是否存在    -(BOOL ...

  6. IOS 获取.plist文件的数据

      @property (nonatomic,strong) NSArray *apps; //获取.plist数据 /**获取plist文件的数组数据*/ -(NSArray *)apps{ if( ...

  7. IOS - 本地数据持久化

    转:相对复杂的App仅靠内存的数据肯定无法满足,数据写磁盘作持久化存储是几乎每个客户端软件都需要做的.简单如“是否第一次打开”的BOOL值,大 到游戏的进度和状态等数据,都需要进行本地持久化存储.这些 ...

  8. iOS数据持久化存储

    本文中的代码托管在github上:https://github.com/WindyShade/DataSaveMethods 相对复杂的App仅靠内存的数据肯定无法满足,数据写磁盘作持久化存储是几乎每 ...

  9. iOS开发——UI基础-懒加载,plist文件,字典转模型,自定义view

    一.懒加载 只有使用到了商品数组才会创建数组 保证数组只会被创建一次 只要能够保证数组在使用时才创建, 并且只会创建一次, 那么我们就称之为懒加载 lazy - (void)viewDidLoad 控 ...

随机推荐

  1. phonegap android3.5.1 Crosswalk

    1. your phonegap platform for android update 3.5.1 cordova platform add android@3.5 2. download cros ...

  2. c# winform 关于DataGridView的一些操作(很全,绝对够用)

    转自:http://heisetoufa.iteye.com/blog/405317 设置字段名 设置字段值 设定单元格表示 Error图标 设定当前单元格 取得当前单元格内容 取得当前单元格的列 I ...

  3. ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

    这个问题, 估计是由于  在 64位系统上运行 C#.net 项目的问题. 试试,将项目 生成属性 中的 平台改成  X86  编译重新发布试试

  4. Android窗口跳转

    1.原始界面 package com.fish.helloworld; import android.app.Activity; import android.content.Intent; impo ...

  5. Conditional Counting In SQL

      If you ever want to conditionally count the number of times a particular condition occurs in SQL, ...

  6. WCF帮助类

    using BJSW.ZTFX.Client.Silverlight.MapBusinessService; using System.ServiceModel; using System.SL.Ap ...

  7. 兼容ie7的导航下拉菜单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. Spring中Quartz调度器的使用

    一.Quartz的特点 * 按作业类的继承方式来分,主要有以下两种: 1.作业类继承org.springframework.scheduling.quartz.QuartzJobBean类的方式 2. ...

  9. (转)Arcgis API常用接口调用方法

    var map, navToolbar, editToolbar, tileLayer, toolbar;//var mapBaseUrl = "http://localhost:8399/ ...

  10. phpcms 的实用相关接口,函数,调用方法

    常用函数 , 打开include/global.func.php,下面存放一些公共函数view plaincopy to clipboardprint? strip_tags() 调用内容过滤html ...