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

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

關于沙盒的讀寫文件的幾種方式

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

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    //    h獲取應用沙盒

    NSString *homaPath =  NSHomeDirectory();

    NSLog(@"%@",homaPath);

}

 

/**

 * 下面的是用  plist  方式 保存 數據

 */

-(void)savePlist{

    NSString *homePath =  NSHomeDirectory();

    NSString *filePath = [homePath stringByAppendingPathComponent:@"Docments"];

    

    //    指定文件格式

    NSString *format = [filePath stringByAppendingPathComponent:@"xx.plist"];

    NSArray *data = @[@"房蘭峰1",@"房蘭峰2"];

    

    [data writeToFile:format atomically:YES];

 

    //    下面的是第二種方式---》系統提供的

    NSString *dataPath =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];

    NSString *filePathNssear = [dataPath stringByAppendingPathComponent:@"xx.plist"];

}

 

/**

 * 下面的是  plist 讀取 數據

 */

-(void)readPlist{

    //  指定是哪個文件

    NSString *homePath = NSHomeDirectory();

    NSString *filePath = [homePath stringByAppendingPathComponent:@"Documents"];

    //    獲取數據

    NSArray *data =  [NSArray arrayWithContentsOfFile:filePath];

}

 

 

//PReference 方式  --->  偏好設置

-(void)preferenceSave{

    

    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];

    

    [ud setObject:@"value11" forKey:@"key1"];

    [ud setObject:@"value2" forKey:@"key2"];

    

    //    同步,一定要寫這一步

    [ud synchronize];

}

/**

 * 下面是  preference  的讀取方式

 */

-(void)preferenceRead{

    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];

    NSLog(@"%@",[ud objectForKey:@"key1"]);

    

}

/**

 * 數據的存儲與讀取 ====   >>>>>>   歸檔與解檔

 */

-(void)keyedArchiverWrite{

    

    NSString *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];

    NSString *filePath = [docPath stringByAppendingPathComponent:@"xx.data"];

    Teacher *teacher = [[Teacher alloc] init];

    teacher.name = @"垃圾";

    teacher.age = 10;

    

    //    歸檔

    [NSKeyedArchiver archiveRootObject:teacher toFile:filePath];

    

}

 

 

-(void)keyedUnarchiverRead{

    

    NSString *filePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];

    NSString *documentType = [filePath stringByAppendingPathComponent:@"xx.data"];

    Teacher *taecher =  [NSKeyedUnarchiver unarchiveObjectWithFile:documentType];

    

}

 

 

@end

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 景洪市| 内丘县| 建宁县| 十堰市| 五华县| 大同县| 岚皋县| 吕梁市| 通许县| 哈尔滨市| 瓦房店市| 颍上县| 赞皇县| 黄陵县| 特克斯县| 衡阳市| 佛冈县| 吕梁市| 聊城市| 定边县| 历史| 平舆县| 琼海市| 广南县| 余姚市| 沙河市| 巨鹿县| 石阡县| 武宣县| 乌拉特前旗| 华安县| 双鸭山市| 循化| 原平市| 开原市| 永安市| 郁南县| 敦煌市| 灵丘县| 阿克陶县| 宣化县|