Created
April 23, 2014 08:41
-
-
Save neonichu/11207364 to your computer and use it in GitHub Desktop.
NSKeyedArchiver with circular arrays
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
| NSMutableArray* bar = [@[] mutableCopy]; | |
| NSArray* foo = @[ bar ]; | |
| [bar addObject:foo]; | |
| //NSLog(@"%@", foo); | |
| NSString *fileName = [NSString stringWithFormat:@"%@_%@", | |
| [[NSProcessInfo processInfo] globallyUniqueString], @"file.data"]; | |
| NSURL* tempfileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() | |
| stringByAppendingPathComponent:fileName]]; | |
| NSMutableData *data = [NSMutableData data]; | |
| NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; | |
| [foo encodeWithCoder:archiver]; | |
| [archiver finishEncoding]; | |
| [data writeToURL:tempfileURL atomically:YES]; | |
| NSData *readData = [NSData dataWithContentsOfURL:tempfileURL]; | |
| NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:readData]; | |
| NSArray* moo = [[NSArray alloc] initWithCoder:unarchiver]; | |
| [unarchiver finishDecoding]; | |
| NSLog(@"%@", moo); |
Author
Author
Documentation seems to suggest it should work with NSKeyedArchiver, just not with NSCoder.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This crashes when logging
moowithSo I can archive but not unarchive a circular graph?