数据持久化,常见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. Leetcode001 two sum

    /* c++ STL is much nore than what i think before in these aspects: * initializer for node element in ...

  2. 在AX4.0中使用C#脚本的实现

    1,虽然ms收购了ax,但是在ax低版本(ver<=4.0)中,还没有办法直接使用ms现在主推的.net技术. 通常的做法是现在AX中天津.net的引用,然后才能在代码中使用.net的一些对象以 ...

  3. 连接器|网络滤波连接器|电脑连接器|RJ45变压器-华联威电子有限公司

    连接器|网络滤波连接器|电脑连接器|RJ45变压器-华联威电子有限公司  

  4. 问 如何使用css将select的边框以及右边的小三角形去掉?

    最好css2,css3都给出解决方案,效果如下: CSS2 只能使用div和ul进行模拟了,结构很简单,具体可参考Alice的 button-dropdownCSS3 可以使用CSS3的属性appea ...

  5. CSS 三角形绘制方法

    #triangle-up {    width: 0;    height: 0;    border-left: 50px solid transparent;    border-right: 5 ...

  6. 【Framework】深入研究Asp.net页面的生命周期

    介绍 Asp.net是微软.Net战略的一个组成部分.它相对以前的Asp有了很大的发展,引入了许多的新机制.本文就Asp.net页面的生命周期向大家做一个初步的介绍,以期能起到指导大家更好.更灵活地操 ...

  7. Secure your iPhone with 6 digit passcode by upgrading to iOS9

    IP-Box could crack 4 digit passcode, what about 6 digit passcode??? All you need to do is to upgrade ...

  8. poj2000

    为了凑今天的数,大水题.不解释了,说来惭愧. #include <stdio.h> int main(){ int n; int i,cnt,j; int tot; while(~scan ...

  9. SQL笔记-第一章,数据库入门

    DBMS的分类DB2.Oracle.Microsoft SQL Server.Sybase SQLServer.Informix.MySQL数据库的结构元素库 database表 table列 col ...

  10. C++ 必知必会:条款15 成员的指针并非指针

    指向类成员的类成员的指针说是“指针”,其实是不合适的,因为他既不包含地址,其行为也不像指针 常规的指正,包含地址,对其解应用可以得到该指针包含地址所指向的对象 1: int a = 12: 2: in ...