***************plist存储

// 当点点击保存的时候调用     //保存
- (IBAction)save:(id)sender {
// 获取沙盒的根路径
// NSString *home = NSHomeDirectory(); // 拼接Documents路径
// NSString *docPath = [home stringByAppendingString:@"/Documents"];
//NSString *docPath = [home stringByAppendingPathComponent:@"Documents"]; /**
* NSDocumentDirectory : 查找Documents文件夹
NSUserDomainMask : 在用户的应用程序下查找
YES 把路径展开 NO 当前应用的根路径 == ~
NO ~/Documents */
NSString *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[];
NSLog(@"%@",docPath); // 拼接文件路径
NSString *filePath = [docPath stringByAppendingPathComponent:@"data.plist"]; // 只有具备writeToFile:的对象才能使用plist存储,NSArray
NSArray *array = @[@,@,@""]; [array writeToFile:filePath atomically:YES]; //NSLog(@"%@",docPath); } //当点击读取的时候调用 读取
- (IBAction)read:(id)sender {
NSString *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[];
NSLog(@"%@",docPath); // 拼接文件路径
NSString *filePath = [docPath stringByAppendingPathComponent:@"data.plist"]; NSArray *data = [NSArray arrayWithContentsOfFile:filePath];
NSLog(@"%@",data); }

********篇好设置

// 保存
- (IBAction)save:(id)sender { // [NSUserDefaults standardUserDefaults]可以直接操作偏好设置文件夹
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; // 自动帮我们生成一个plist文件存放在偏好设置的文件夹
[defaults setObject:@"hm" forKey:@"account"]; // 同步:把内存中的数据和沙盒同步
[defaults synchronize]; } //读取
- (IBAction)read:(id)sender {
// [NSUserDefaults standardUserDefaults]可以直接操作偏好设置文件夹
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSLog(@"%@",[defaults objectForKey:@"account"]); // NSDictionary *dict = @{@"account":@"hm"};
//
// dict writeToFile:<#(NSString *)#> atomically:<#(BOOL)#> }

***************对象归档

******persion.m

#import "HMPerson.h"

@implementation HMPerson

// 在对象归档的时候调用
// 哪些属性需要归档
// 这些属性怎么归档
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeInt:_age forKey:@"age"];
} // 在对象解档的时候调用
// 哪些属性需要解档
// 这些属性怎么解档 - (id)initWithCoder:(NSCoder *)aDecoder
{
// 当父类实现了NSCoding,就能调用 [super initWithCoder]
if (self = [super init]) {
_age = [aDecoder decodeIntForKey:@"age"];
}
return self;
} @end

****归档的保存和读取

//保存
@implementation HMViewController - (IBAction)save:(id)sender {
HMPerson *person = [HMPerson new];
person.age = ; NSString *docPath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[]; // 拼接文件路径
NSString *filePath = [docPath stringByAppendingPathComponent:@"person.data"]; [NSKeyedArchiver archiveRootObject:person toFile:filePath]; }
//读取
- (IBAction)read:(id)sender {
NSString *docPath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[]; // 拼接文件路径
NSString *filePath = [docPath stringByAppendingPathComponent:@"person.data"]; HMPerson *p = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
NSLog(@"%d",p.age);
}

IOS第13天(2,私人通讯录,plist存储,偏好设置,归档)的更多相关文章

  1. IOS第13天(3,私人通讯录,登陆状态数据存储,数据缓存, cell的滑动删除,进入编辑模式,单个位置刷新 )

    *****联系人的界面的优化 HMContactsTableViewController.m #import "HMContactsTableViewController.h" # ...

  2. IOS第13天(1,私人通讯录,登陆功能,界面的跳转传值,自定义cell,编辑界面)

    ******HMLoginViewController 登陆的界面 #import "HMLoginViewController.h" #import "MBProgre ...

  3. 持久化存储——偏好设置,plist,归档---学习笔记二

    //一. 本地持久化 //1.沙盒 //1.1 应用程序包:存放的是应用程序的源文件,包括资源文件和可执行文件 NSString *path = [[NSBundle mainBundle]bundl ...

  4. 数据存储之plist、偏好设置

    // 偏好设置--------------------------------- // 存储基本类型数据 NSUserDefaults *defaults = [NSUserDefaults stan ...

  5. 1211笔记关于//modal//更改窗口的根控制器//数据存取//Plist属性列表//-“沙盒机制”//plis属性列表//偏好设置//归档普通对象//联系人数据存储//协议与回调函数

    一.利用Modal形式展示控制器 1.如何展示// vc就是要展示的新控制器[self presentViewController:vc animated:YES completion:^{    N ...

  6. ios应用数据存储方式(偏好设置)-转

    一.简单介绍 1.很多ios应用都支持偏好设置,比如保存用户名,密码,字体大小等设置,ios提供了一套标准的解决方案来为应用加入偏好设置功能. 2.每个应用都有个NSUserDefaults实例,通过 ...

  7. [iOS基础控件 - 6.11.3] 私人通讯录Demo 控制器的数据传递、存储

    A.需求 1.搭建一个"私人通讯录"Demo 2.模拟登陆界面 账号 密码 记住密码开关 自动登陆开关 登陆按钮 3.退出注销 4.增删改查 5.恢复数据(取消修改)   这个代码 ...

  8. IOS学习之-私人通讯录

    通过一段时间IOS的学习完成了一个简单的应用,"私人通讯录". 运行效果如下图: 1.登录页 2.通讯录列表 3.添加 4.编辑 5.删除 6.注销 总视图结构如下图: 总结本程序 ...

  9. iOS开发——UI进阶篇(十一)应用沙盒,归档,解档,偏好设置,plist存储,NSData,自定义对象归档解档

    1.iOS应用数据存储的常用方式XML属性列表(plist)归档Preference(偏好设置)NSKeyedArchiver归档(NSCoding)SQLite3 Core Data 2.应用沙盒每 ...

随机推荐

  1. jquery mousewheel

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js&quo ...

  2. html中frameset的详细使用方法

    http://blog.csdn.net/csb5201314/article/details/5695417

  3. Spring Integration - 自动轮询发送手机短信

    Spring Integration 配置 <?xml version="1.0" encoding="UTF-8"?> <beans xml ...

  4. Posterior visual bounds retrieval for the Plato framework

    Plato is a MVVM compliant 2D on-canvas graphics framework I've been designing and implementing for d ...

  5. 快速搭建IE测试环境(Virtualbox+ievms)

    IE下的测试 作为一个有追求的程序员,应该尽可能的远离Windows系统.不论从专业开发者的角度,还是仅仅作为最终用户从使用体验上来说,Windows都可以算是垃圾中的战斗机: 没有shell . 响 ...

  6. 【HDU】3516 Tree Construction

    http://acm.hdu.edu.cn/showproblem.php?pid=3516 题意:平面n个点且满足xi<xj, yi>yj, i<j.xi,yi均为整数.求一棵树边 ...

  7. 【CodeVS】p1174 靶形数独

    题目描述 Description 小城和小华都是热爱数学的好学生,最近,他们不约而同地迷上了数独游戏,好胜的他们想用数独来一比高低.但普通的数独对他们来说都过于简单了,于是他们向Z 博士请教,Z 博士 ...

  8. 省略文字的css

    在显示一行文字时,如果容器太小,为了显示出省略字符,可以使用 ellipsis { white-space: nowrap; overflow: hidden; text-overflow: elli ...

  9. BZOJ4499: 线性函数

    Description 小C最近在学习线性函数,线性函数可以表示为:f(x) = kx + b.现在小C面前有n个线性函数fi(x)=kix+bi ,他对这n个线性函数执行m次操作,每次可以: 1.M ...

  10. SDCycleScrollView 滚动视图的使用(广告)

    github库链接https://github.com/gsdios/SDCycleScrollView 无限循环自动图片轮播器(一步设置即可使用) // 网络加载图片的轮播器 cycleScroll ...