iOS防止消息转发的crash
iOS开发时经常会遇到消息转发的crash,控制台会输出类似下面的提示:
-[__NSCFNumber lowercaseString]:unrecognized selector sent to instance 0x87
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',reason :'[__NSCFNumber lowercaseString]: unrecognized selector sent to instance 0x87'
上面这段异常信息是有NSObject的”doesNotRecognizeSelector:” 方法所抛出的,此异常表明:消息接收者的类型是__NSCFNumber,而该接收者无法理解名为lowercaseString的选择子。为了这中情况不使程序崩溃,我们可以在转发消息的过程中设置钩子,用以执行预定的逻辑。