当前位置:   article > 正文

nserror 自定义错误_iOS NSError详解 NSError错误code对照表 自定义、定制NSError 一看就懂...

nslog nserror

*localizedrecoveryoptions;本地恢复建议

@property (nullable, readonly, strong) id recoveryattempter;

@property (nullable, readonly, copy) nsstring *helpanchor;

预定义的userinfo键名

nsstring *const nsunderlyingerrorkey;//推荐的标准方式,通用键

nsstring *const nslocalizeddescriptionkey; //

详细描述键

nsstring *const nslocalizedfailurereasonerrorkey; // 失败原因键

nsstring *const nslocalizedrecoverysuggestionerrorkey; //恢复建议键

nsstring *const nslocalizedrecoveryoptionserrorkey; // 恢复选项键

//其他键

nsstring *const nsrecoveryattemptererrorkey;

nsstring *const nshelpanchorerrorkey;

nsstring *const nsstringencodingerrorkey ;

nsstring *const nsurlerrorkey;

nsstring *const nsfilepatherrorkey;

用法示例:

nsdictionary *userinfo1 = [nsdictionary dictionarywithobjectsandkeys:@"由于文件不存在,无法打开", nslocalizeddescriptionkey, @"失败原因:文件不存在", nslocalizedfailurereasonerrorkey, @"恢复建议:请创建该文件",nslocalizedrecoverysuggestionerrorkey,nil];

nserror *error = [[nserror alloc] initwithdomain:nscocoaerrordomain code:4 userinfo:userinfo1];//此处code是4,对照下面对照表4代表文件不存在。userinfo传userinfo1 查看自定义打印。userinfo传nil,查看本地化描述。

nslog(@"========%@",[error localizeddescription]);

nslog(@"========%@",[error localizedfailurereason]);

nslog(@"========%@",[error localizedrecoverysuggestion]);

二、nserror错误code对照表

foundation constants reference

nserror codes

nserror c

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/624547
推荐阅读
相关标签
  

闽ICP备14008679号