国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

數據持久化-Plist文件寫入

2019-11-14 19:55:21
字體:
來源:轉載
供稿:網友

數據持久化,常見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

上一篇:ios–視圖

下一篇:ios開發入門

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 隆昌县| 五寨县| 民丰县| 石城县| 滕州市| 永新县| 盐源县| 连平县| 岢岚县| 富顺县| 永城市| 千阳县| 运城市| 青浦区| 温州市| 来凤县| 博白县| 连州市| 宿松县| 法库县| 宝坻区| 北辰区| 桑植县| 滨海县| 兴化市| 秀山| 株洲县| 安塞县| 安泽县| 余庆县| 灵寿县| 武汉市| 巴青县| 九台市| 兴山县| 固始县| 鹰潭市| 新沂市| 天峻县| 吴旗县| 万荣县|