国产探花免费观看_亚洲丰满少妇自慰呻吟_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開發入門

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 哈尔滨市| 铜陵市| 武隆县| 金川县| 博罗县| 潜江市| 阳曲县| 遂宁市| 鸡泽县| 临颍县| 雷山县| 武宣县| 子洲县| 扶绥县| 汉寿县| 珲春市| 绥化市| 张掖市| 荔波县| 西青区| 嘉禾县| 阆中市| 南华县| 石泉县| 高陵县| 分宜县| 郯城县| 新龙县| 华容县| 久治县| 彭州市| 东乌珠穆沁旗| 英山县| 高密市| 建阳市| 离岛区| 瑞安市| 连平县| 黄平县| 襄樊市| 大冶市|