在Objective-C中,在实现委托/协议方法中,是否将实参类型替换为更具体的(子类)参数类型是好的还是不好的做法?具有更多特定参数类型的Objective-C委托方法
例如,根据用于UIGestureRecognizer的文档:
The action methods invoked must conform to one of the following signatures: - (void)handleGesture; - (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer;
当我添加一个UITapGestureRecognizer到的视图,我知道的参数handleGesture:
将类型的UITapGestureRecognizer(除非另一手势识别是稍后添加)。用UITapGestureRecognizer类型的参数替换UIGestureRecognizer参数会不会不自觉?例如:
- (void)handleGesture:(UITapGestureRecognizer *)gestureRecognizer { // implementation }