2012-04-05 63 views
0
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 

为什么在分配错误对象时崩溃?当我分配NSError userInfo来设置NSDictionary时,为什么我的应用崩溃了?


这里有崩溃的细节:

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

回答

3

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

从文档:

用户信息字典可以有时包括另一个NSError对象 表示在由含有NSError表示的错误 底层的子系统错误。您可以查询此底层的 错误对象以获取有关错误原因的更多特定信息 。

您可以通过使用NSUnderlyingErrorKey字典键来访问基础错误对象。

+0

真诚地,谢谢你的亲切回答。 – 2012-04-05 01:51:18

相关问题