简体   繁体   English

[__NSArrayM getFileSystemRepresentation:maxLength:]:发送到实例的无法识别的选择器

[英][__NSArrayM getFileSystemRepresentation:maxLength:]: unrecognized selector sent to instance

I have the following code to load some files and save them to disk: 我有以下代码加载一些文件并将其保存到磁盘:

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];

    }

    });

}

However, when I run this code, the following exception appears: 但是,当我运行此代码时,会出现以下异常:

在此输入图像描述

* 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: terminate called throwing an exception (lldb) *终止应用程序由于未捕获的异常'NSInvalidArgumentException',原因是: ' - [__ NSArrayM getFileSystemRepresentation:最大长度:]:无法识别的选择发送到实例0xc8809e0' *第一掷调用堆栈:(0x3623012 0x3448e7e 0x36ae4bd 0x3612bbc 0x361294e 0x2e2d7b4 0x2e2d762 0x2e5bc85 0x2e83c7a 0x8d98 0x406053f 0x4072014 0x40632e8 0x4063450 0x95336e12 0x9531ecca)libc ++ abi.dylib:terminate调用抛出异常(lldb)

Why is this happening? 为什么会这样?

It seems that [dictionary objectForKey:@"paths"] on the suspicious line contains an NSMutableArray instead of an NSString . 似乎可疑行上的[dictionary objectForKey:@"paths"]包含NSMutableArray而不是NSString Perhaps you meant [[dictionary objectForKey:@"paths"] objectAtIndex:0] instead. 也许你的意思是[[dictionary objectForKey:@"paths"] objectAtIndex:0]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM