zoukankan      html  css  js  c++  java
  • 归档二

    //

    //  ViewController.m

    //  UI-NO.4

    //

    //  Created by Bruce on 15/7/16.

    //  Copyright (c) 2015年 Bruce. All rights reserved.

    //

    #import "ViewController.h"

    #import "UserModel.h"

    @interface ViewController ()

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        

        /*

        NSArray *arr = @[@"111",@"222"];

        

        NSArray *docs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

        

        NSString *path = [[docs lastObject] stringByAppendingPathComponent:@"my.archiver"];

        

        BOOL success = [NSKeyedArchiver archiveRootObject:arr toFile:path];

        

        if (success) {

            [self showAlertWithMessage:@"成功"];

        }

        

        NSArray *arr1 = [NSKeyedUnarchiver unarchiveObjectWithFile:path];

        NSLog(@"%@",arr1);

        

        */

        /*

         

        NSArray *arr = @[@"111",@"222"];

        

        NSArray *docs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

        

        NSString *path = [[docs lastObject] stringByAppendingPathComponent:@"my.archiver"];

        

        NSMutableData *data = [NSMutableData data];

        NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]initForWritingWithMutableData:data];

        [archiver encodeObject:arr forKey:@"arr"];

        [archiver finishEncoding];

        

        BOOL success = [data writeToFile:path atomically:YES];

        if (success) {

            [self showAlertWithMessage:@"成功"];

        }

        

        NSData *data1 = [NSData dataWithContentsOfFile:path];

        NSKeyedUnarchiver *unArc = [[NSKeyedUnarchiver alloc]initForReadingWithData:data1];

        NSArray *rr = [unArc decodeObjectForKey:@"arr"];

        NSLog(@"%@",rr);

        

        */

        /*

        UserModel *model = [[UserModel alloc]init];

        model.name = @"mmm";

        NSArray *docs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

        

        NSString *path = [[docs lastObject] stringByAppendingPathComponent:@"my.archiver"];

        

        BOOL success = [NSKeyedArchiver archiveRootObject:model toFile:path];

        

        if (success) {

            [self showAlertWithMessage:@"成功"];

        }

        

        UserModel *model1 = [NSKeyedUnarchiver unarchiveObjectWithFile:path];

        NSLog(@"%@",model1.name);

         */

    }

    - (void)showAlertWithMessage:(NSString *)message

    {

        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"文件归档" message:message delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

        [alert show];

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    @end

  • 相关阅读:
    Quartz.Net 学习随手记之04 构建Windows Service承载服务
    Quartz.Net 学习随手记之03 配置文件
    SQL Server问题之计算机名称更改后无法登陆本地数据库
    SQL Server问题之The remote procedure call failed. [0x800706be]
    跨框架菜单menuG5使用
    DLink 524M经常断线、掉线问题的解决
    MSChart使用导航之开发
    ReSharper制作Template帮助我们快速输入代码
    网站右下角弹出通知效果的制作
    Dell6400拆卸与维护
  • 原文地址:https://www.cnblogs.com/wukun16/p/4883949.html
Copyright © 2011-2022 走看看