数据持久化-Plist文件写入
数据持久化,常见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文件写入的更多相关文章
- 写入数据到Plist文件中时,第一次要创建一个空的数组,否则写入文件失败
#pragma mark - 保存数据到本地Plist文件中 - (void)saveValidateCountWithDate:(NSString *)date count:(NSString *) ...
- IOS开发--数据持久化篇文件存储(二)
前言:个人觉得开发人员最大的悲哀莫过于懂得使用却不明白其中的原理.在代码之前我觉得还是有必要简单阐述下相关的一些知识点. 因为文章或深或浅总有适合的人群.若有朋友发现了其中不正确的观点还望多多指出,不 ...
- python(四)数据持久化操作 文件存储
1.写入 导入pickle包 然后组织一个列表my_list,保存为pkl格式,可以是任意格式 在磁盘下回出现一个保存的文件 2.读取
- Android数据持久化技术 — — —文件存储
文件保存 package com.example.datastroredtest; import android.app.Activity;import android.os.Bundle;impor ...
- iOS开发——数据持久化OC篇&plist文件增删改查操作
Plist文件增删查改 主要操作: 1.//获得plist路径 -(NSString*)getPlistPath: 2.//判断沙盒中名为plistname的文件是否存在 -(BOOL ...
- IOS 获取.plist文件的数据
@property (nonatomic,strong) NSArray *apps; //获取.plist数据 /**获取plist文件的数组数据*/ -(NSArray *)apps{ if( ...
- IOS - 本地数据持久化
转:相对复杂的App仅靠内存的数据肯定无法满足,数据写磁盘作持久化存储是几乎每个客户端软件都需要做的.简单如“是否第一次打开”的BOOL值,大 到游戏的进度和状态等数据,都需要进行本地持久化存储.这些 ...
- iOS数据持久化存储
本文中的代码托管在github上:https://github.com/WindyShade/DataSaveMethods 相对复杂的App仅靠内存的数据肯定无法满足,数据写磁盘作持久化存储是几乎每 ...
- iOS开发——UI基础-懒加载,plist文件,字典转模型,自定义view
一.懒加载 只有使用到了商品数组才会创建数组 保证数组只会被创建一次 只要能够保证数组在使用时才创建, 并且只会创建一次, 那么我们就称之为懒加载 lazy - (void)viewDidLoad 控 ...
随机推荐
- ref传递
下面通过一个排序的小栗子来分析ref传递: static void Main(string[] args) { ,,,,}; int num; Console.WriteLine("请输入您 ...
- json 對象的序列化
var a={x:1,y:2} s=JSON.stringify(a); //s="{"x":1,"y":2}" p=JSON.parse( ...
- Oracle笔记 十一、PL/SQL函数和触发器
--创建函数 create or replace function add_sal(sSal number) return number is begin if (sSal > 5000) th ...
- CThreadPool
class CThreadPool { public: template <typename T> static void QueueUserWorkItem(void (T::*func ...
- Magento修改css样式更新之——grunt命令使用
1.清除pub/static和var中相应文件 2.源头文件重新导入pub/static 3.pub中的less编译 4.字面翻译是跟踪源头文件变化实时编译,但是这里的the source files ...
- SQL server 性能调优
转自: http://www.cnblogs.com/MR_ke/archive/2010/08/25/1807856.html sql 2005性能调优 SQL Server在运行一段时间,随着数据 ...
- hadoop,hbase,pig安装
注意端口,办公网只能访问8000-9000的端口 pig的一些lib文件版本 /home/map/hadoop/lib下一些98.5的lib没删除
- pect-shell中的自动交互
这是我在ST写的自动登陆ssh的脚本, 分两个文件 文件1: sssh #!/bin/bash #xql 2011/01/4#auto ssh 138.198.230.170 case $1 in & ...
- MySQL的存储引擎整理
01.MyISAM MySQL 5.0 以前的默认存储引擎.MyISAM 不支持事务.也不支持外键,其优势是访问的速度快,对事务完整性没有要求或者以SELECT.INSERT 为主的应用基本上都可以使 ...
- node中的流程控制中,co,thunkify为什么return callback()可以做到流程控制?
前言 我在学习generator ,yield ,co,thunkify的时候,有许多费解的地方,经过了许多的实践,也慢慢学会用,慢慢的理解,前一阵子有个其他项目的同事过来我们项目组学习node,发现 ...