Re: Private Methods
Re: Private Methods
- Subject: Re: Private Methods
- From: Jens Alfke <email@hidden>
- Date: Tue, 18 Aug 2015 11:48:41 -0700
> On Aug 18, 2015, at 11:32 AM, Maxthon Chan <email@hidden> wrote:
>
> The compiler knows absolutely NOTHING.
The (Obj-C) compiler knows if a superclass declares a method with the same selector. So in some cases it can tell that you’re overriding. The problem is that it can’t tell if your method overrides a _non-public_ method in a superclass. That information is only in the superclass’s compiled code, not in the headers, so it isn’t available at compile time. (And it’s possible for the superclass method to be added at runtime, in which case not even the framework binary would show that exists!)
It would be possible to add an “override” flag to the method metadata; then when a class is being loaded the runtime could check whether it has a method without that flag that will actually override a superclass method, and if so signal some sort of failure. This won’t catch the cases where methods get inserted into the superclass after the subclass is loaded, but it will catch the most common causes of problems.
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden