下面给了一个判断函数是否实现,如果没有实现就报错的功能代码
//判断函数是否实现:
Bool isImplement = [sel respondsToSelector:@selector(RQtableView:numberOfRowsInSection:)];
//获取当前的函数名:
NSString *selectorName = NSStringFromSelector(_cmd);
//获取当前的类名:
NSString *className = NSStringFromClass(self.class);
//如果函数没有实现,打印当前类(这个类通常是我们继承的子类,比如的继承的UIviewController:RQViewController,那么打印的类名就是“RQViewController”),
NSString *excpt NSStringFromSelector(_cmd) = [NSString stringWithFormat:@"--->class: '%@' is not implement method: RQtableView:numberOfRowsInSection:''<---",NSStringFromClass(self.class)];
NSLog(@"%@",class)
//
//isImplement == NO,如果当前类没有实现函数的话,就会报错
NSAssert(isImplement,className);
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '--->class: 'MyHonorViewController' is not implement method: 'RQtableView:numberOfRowsInSection:'<---'