ios NSKeyedArchiver 保存对象与对象数组

废话不说,直接上代码

 1 //
 2 //  CommunityTool.h
 3 //  SmartCommunity
 4 //
 5 //  Created by chenhuan on 15/9/2.
 6 //  Copyright (c) 2015年 smartcommunity. All rights reserved.
 7 //
 8 
 9 #import <Foundation/Foundation.h>
10 @interface CommunityTool : NSObject
11 + (void)SaveComunity:(NSArray *)homepageBeans;
12 + (NSMutableArray *)HomePageBean;
13 @end
 1 //
 2 //  CommunityTool.m
 3 //  SmartCommunity
 4 //
 5 //  Created by chenhuan on 15/9/2.
 6 //  Copyright (c) 2015年 smartcommunity. All rights reserved.
 7 //
 8 
 9 #import "CommunityTool.h"
10 
11 #define SChomepagePath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"homepage.archive"]
12 
13 @implementation CommunityTool
14 + (void)SaveComunity:(NSArray *)homepageBeans{
15     [NSKeyedArchiver archiveRootObject:homepageBeans toFile:SChomepagePath];
16 }
17 + (NSMutableArray *)HomePageBean{
18     return [NSKeyedUnarchiver unarchiveObjectWithFile:SChomepagePath];
19 }
20 @end

 

posted @ 2015-09-02 16:49  Athook  阅读(660)  评论(0编辑  收藏  举报