【问题标题】:Why is my app crashing when I allocate NSError userInfo to set a NSDictionary?当我分配 NSError userInfo 来设置 NSDictionary 时,为什么我的应用程序会崩溃?
【发布时间】:2012-04-05 01:21:17
【问题描述】:
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"Please, other format selected.", NSLocalizedDescriptionKey, @"This format is not available.", NSLocalizedFailureReasonErrorKey, @"The operation couldn't be completed.", NSUnderlyingErrorKey, self.URL, NSURLErrorKey, nil];

NSLog(@"dict:%@", dict); // no Crash

NSError *error = [NSError errorWithDomain:@"testError" code:1 userInfo:dict];// crash

为什么在分配错误对象时会崩溃?


以下是崩溃详情:

+[__NSCFConstantString objectForKey:]: unrecognized selector sent to class 0x3ebf5550

【问题讨论】:

    标签: iphone objective-c nsdictionary nserror


    【解决方案1】:

    IIRC NSUnderlyingErrorKey 应该是 NSError 的另一个实例。

    来自文档:

    用户信息字典有时可以包含另一个 NSError 对象 表示错误基础子系统中的错误 由包含NSError 表示。你可以查询这个底层 错误对象获取有关原因的更具体信息 错误。

    您可以使用 NSUnderlyingErrorKey 字典键访问底层错误对象。

    【讨论】:

    • 此致,感谢您的热心回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-18
    • 1970-01-01
    • 2019-08-11
    • 2017-12-25
    • 1970-01-01
    相关资源
    最近更新 更多