Created
August 7, 2014 01:38
-
-
Save oa414/bebfdbaca5c849ae7abb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SXStoregeHelper.h | |
// sx | |
// | |
// Created by xiangyu on 3/26/14. | |
// Copyright (c) 2014 xiangyu. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
#import "DefaultsKeys.h" | |
@interface SXStoregeHelper : NSObject | |
+(void) setArray : (NSArray *)array key : (NSString *) keyName; | |
+(NSArray *) getArrayWithKey : (NSString *)keyName; | |
+(void) setDictionary : (NSDictionary *)dict key : (NSString *) keyName; | |
+(NSDictionary *) getDictionaryWithKey : (NSString *)keyName; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SXStoregeHelper.m | |
// sx | |
// | |
// Created by xiangyu on 3/26/14. | |
// Copyright (c) 2014 xiangyu. All rights reserved. | |
// | |
#import "SXStoregeHelper.h" | |
@implementation SXStoregeHelper | |
+(void) setArray : (NSArray *)array key : (NSString *) keyName{ | |
NSData *arrayData = [NSKeyedArchiver archivedDataWithRootObject:array]; | |
[[NSUserDefaults standardUserDefaults] setObject:arrayData forKey:keyName]; | |
[[NSUserDefaults standardUserDefaults] synchronize]; | |
} | |
+(NSArray *) getArrayWithKey : (NSString *)keyName{ | |
NSData *arrayData = [[NSUserDefaults standardUserDefaults] objectForKey:keyName]; | |
NSArray *array =[NSKeyedUnarchiver unarchiveObjectWithData:arrayData]; | |
return array; | |
} | |
+(void) setDictionary : (NSDictionary *)dict key : (NSString *) keyName{ | |
NSData *dictData = [NSKeyedArchiver archivedDataWithRootObject:dict]; | |
[[NSUserDefaults standardUserDefaults] setObject:dictData forKey:keyName]; | |
[[NSUserDefaults standardUserDefaults] synchronize]; | |
} | |
+(NSDictionary *) getDictionaryWithKey : (NSString *)keyName{ | |
NSData *arrayData = [[NSUserDefaults standardUserDefaults] objectForKey:keyName]; | |
NSDictionary *dict =[NSKeyedUnarchiver unarchiveObjectWithData:arrayData]; | |
return dict; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment