いくつかのファイルをロードしてディスクに保存する次のコードがあります。
NSDictionary *dictionary = [NSKeyedUnarchiver unarchiveObjectWithData:[NSData dataWithContentsOfURL:url]];
// THE LINE BELOW IS WHERE THE EXCEPTION OCCURS
NSMutableArray *paths = [[NSMutableArray alloc] initWithArray:[NSKeyedUnarchiver unarchiveObjectWithFile:[dictionary objectForKey:@"paths"]]];
if(dictionary)
{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"DOWNLOADED PATHS: %@", paths);
NSFileManager *filemgr;
NSString *docsDir;
NSArray *dirPaths;
filemgr = [NSFileManager defaultManager];
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
for(NSObject *obj in paths)
{
NSString *identification = [defaults objectForKey:@"LatestID"];
NSString *pageno = [NSString stringWithFormat:@"%i", [paths indexOfObject:obj]];
NSString *name = [NSString stringWithFormat:@"%@paths%@.archive", identification, pageno];
NSString *dataFilePath = [[NSString alloc] initWithString: [docsDir
stringByAppendingPathComponent:name]];
[NSKeyedArchiver archiveRootObject:paths toFile:dataFilePath];
}
});
}
ただし、このコードを実行すると、次の例外が表示されます。
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM getFileSystemRepresentation:maxLength:]: unrecognized selector sent to instance 0xc8809e0' * First throw call stack: (0x3623012 0x3448e7e 0x36ae4bd 0x3612bbc 0x361294e 0x2e2d7b4 0x2e2d762 0x2e5bc85 0x2e83c7a 0x8d98 0x406053f 0x4072014 0x40632e8 0x4063450 0x95336e12 0x9531ecca) libc++abi.dylib: 例外をスローして呼び出された終了 (lldb)
なぜこうなった?