Last active
February 3, 2016 06:08
-
-
Save ryu1/c9f6e415fa59d05f010b to your computer and use it in GitHub Desktop.
NSUserDefaults+Extension.m
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
| // | |
| // NSUserDefaults+Extension.h | |
| // | |
| // Created by Ryuichi Ishitsuka on 2016/01/29. | |
| // | |
| #ifndef NSUserDefaults_Extension_h | |
| #define NSUserDefaults_Extension_h | |
| @interface NSUserDefaults (Extension) | |
| /* | |
| オブジェクトをシリアライズしてセットします。 | |
| @param encodableObject シリアライズ可能なオブジェクト | |
| @param key | |
| */ | |
| - (void) setObjectAsData:(id)encodableObject forKey:(NSString *)key; | |
| /* | |
| オブジェクトをデシリアライズして取得します。 | |
| @param key | |
| @return オブジェクト | |
| */ | |
| - (id) objectFromDataWithKey:(NSString*)key; | |
| @end | |
| #endif /* NSUserDefaults_Extension_h */ |
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
| // | |
| // NSUserDefaults+Extension.m | |
| // | |
| // Created by Ryuichi Ishitsuka on 2016/01/29. | |
| // | |
| #import <Foundation/Foundation.h> | |
| @implementation NSUserDefaults (Extension) | |
| - (NSUserDefaults *) defaults { | |
| return [NSUserDefaults standardUserDefaults]; | |
| } | |
| - (void) setObjectAsData:(id)encodableObject forKey:(NSString *)key { | |
| NSData *data = [NSKeyedArchiver archivedDataWithRootObject:encodableObject]; | |
| [self.defaults setObject:data forKey:key]; | |
| } | |
| - (id) objectFromDataWithKey:(NSString*)key { | |
| NSData *data = [self.defaults objectForKey:key]; | |
| return [NSKeyedUnarchiver unarchiveObjectWithData:data]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment