数据持久化-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 控 ...
随机推荐
- PC上安装MAC X Lion
PC上安装MACXLion 网上关于如何在PC下安装MAC的文章已近不少了,但对于一些初学者在实践当中会遇到各种问题,以下视频资料为大家展示两种虚拟机安装MacOS. 1.VmwareWorkstat ...
- MFC读取XML文件并解析
现在经常会对XML文件进行操作,怎么在MFC下去读和解析XML文件呢?直接上代码: 首先得等在stdafx.h中加入这句,以引入MSXML命名空间 #import <msxml3.dll> ...
- 查询Sql Server Agent 的job的执行情况。
//有关SqlJob的信息在database(msdb)内查询.select j.job_id, j.name, j.enabled, jh.run_status, js.last_outcome_m ...
- python3.5在print和input上的几个变化
1. 在python3.5中使用print,打印内容必须用括号()括起来.python2.7中可以不用括号,如果你加了括号,代码在python2.7中也是可以正常运行的. python3.5 exam ...
- 序列化和反序列化,异步调用web/wcf/函数
//xml序列化 public static string Seria(DataSet ds) { XmlSerializer serializer = new XmlSerializer(typeo ...
- 【.NET】对文件的对称加密
using System;using System.IO;using System.Security.Cryptography;namespace ConsoleApp_SymmetricalEncr ...
- leetcode 107
107. Binary Tree Level Order Traversal II Given a binary tree, return the bottom-up level order trav ...
- leetcode 100
100. Same Tree Given two binary trees, write a function to check if they are equal or not. Two binar ...
- Chrome不能登录和同步的解决方法
打开 C:\Windows\System32\drivers\etc 下的 hosts文件 #SmartHosts START #Google Services START .docs.google. ...
- jQuery实现跨域访问
示例: $.ajax({ url: url, crossDomain: true, async: false,dataType:"jsonp" }); 说明:$.ajax()有很多 ...