Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- scale
- .svn
- ccbi
- 멀티태스킹
- release
- LLVM
- Undefined symbols for architecture armv7s
- xib
- Default-568h.png
- SBTarget
- CCLOG
- storyboard
- UIView
- cocos2d-x
- 태그를 입력해 주세요.
- box2d
- landscape
- NSHomeDirectory
- Xcode
- Derived Data
- /var/mobile/Applications
- Debug
Archives
- Today
- Total
standwally
NSKeyedArchiver/NSKeyedUnarchiver 본문
데이터를 보관하기 위한 용도로 쓰이는 클래스 입니다.
NSKeyedArchiver의 사용방법은 인코딩과 디코딩 단계로 이루어집니다.
1. Encoding
NSArray* array = [[NSArray alloc] initWithArray:NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)]; NSString* strPath = [NSString stringWithFormat:@"%@/KeyedArchive", [array objectAtIndex:0]]; NSString* str = [NSString stringWithFormat:@"Hello!!!"]; NSMutableData* mutableData = [NSMutableData data]; NSKeyedArchiver* archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:mutableData]; [archiver encodeObject:str forKey:@"Key"]; [archiver finishEncoding]; BOOL result = [mutableData writeToURL:[NSURL fileURLWithPath:strPath] atomically:YES]; if (result) { NSLog(@"Success!!"); }
2. Decoding
NSArray* array = [[NSArray alloc] initWithArray:NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)]; NSString* strPath = [NSString stringWithFormat:@"%@/KeyedArchive", [array objectAtIndex:0]]; NSData* data = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:strPath]]; NSKeyedUnarchiver* archiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; NSString* str = [archiver decodeObjectForKey:@"Key"]; [archiver finishDecoding]; if (str) { NSLog(@"Decoded Value : %@", str); } else { NSLog(@"Failed!"); }