unrecognized selector sent to instance报错总结

用途:根据报错调用的方法名来快速估计出错的位置,可能某个对象被当作另一个对象使用了

报错例子:
-[UIView setSelected:]: unrecognized selector sent to instance 0x7ff3f35b1070
可能是误将uiview当UIButton使用,调用了setSelected

注:Person为NSObject
-[Person length]: unrecognized selector sent to instance 0x7ff3f35b1070
错误将Person当做NSString来使用,比如
id obj = [[Person alloc] init];
NSString *string = obj;
string.length;

-[Person count]: unrecognized selector sent to instance 0x7ff3f35b1070
误将Person当数组使用
id obj = [[Person alloc] init];
NSArray *array = obj;
array.count;

-[Person setObject:forKeyedSubscript:]: unrecognized selector sent to instance 0x7ff3f35b1070
错误将Person当做NSMutableDictionary来使用

规律: 方法名里面包含了Subscript的方法,一般都是集合的方法(比如字典\数组)

你可能感兴趣的:(unrecognized selector sent to instance报错总结)