在ObjC中,如何在子类中隐藏超类方法的实现? [英] In ObjC, how do I hide implementation a superclass's methods in a subclass?
问题描述
在ObjC中,如何在子类中隐藏超类方法的实现?
In ObjC, how do I hide implementation a superclass's methods in a subclass?
我不确定@private是否可以解决问题,因为它似乎仅适用于ivars.
I'm not sure if @private would do the trick, as it appears to only apply to ivars.
推荐答案
Obj-C中没有实际上私有"方法;由于可以在运行时将任何消息发送到任何对象,因此无法阻止某人发送您关心的消息.
There are no actually "private" methods in Obj-C; since any message can be sent to any object at runtime, there's no way to prevent someone from sending the message you care about.
也就是说,您可以在子类中拦截该消息,而不处理它.使超类的方法不可访问的最简单方法是在子类中重写它,而不执行任何操作:
That said, you can intercept that message in the subclass and not handle it. The simplest way to make a superclass's method inaccessible is to override it in the subclass and do nothing:
- (void)someMethodIDontWantToSupport
{
}
这篇关于在ObjC中,如何在子类中隐藏超类方法的实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!