Le 7 nov. 2011 à 08:49, Joar Wingfors a écrit :

> 
> On 6 nov 2011, at 14:10, Bryan Harrison wrote:
> 
>> I'm a total tyro and hope nobody minds if I fire off the occasional 
>> incredibly elementary question.  
>> 
>> I'm reviewing some sample code and am looking at a class with a method 
>> declared in @implementation which isn't mentioned in any @interface.
>> 
>> Is this a private method, something else entirely, or merely sloppy coding?  
>> 
>> If the former, how does this technique compare with the trick of putting an…
>> 
>> @interface someClass ()
>> - (type) somePrivateMethod;
>> @end
>> 
>> …in the implementation?
> 
> 
> Hello Bryan,
> 
> That would be a private method, or - like Graham pointed out - an override of 
> a method from a superclass. I guess it could also be "dead" code (not called 
> from anywhere), but that's typically not very likely.
> 
> In OjbC you don't need to provide declarations for a method "foo" if all 
> callers of foo can "see" the definition of foo (ie. if they are themselves 
> defined *after* foo). The definition also serves as a declaration in such a 
> case.

Note that the 'defined after' constraint is merely a compiler limitation. 
Recent clang builds don't require this anymore. You can defined your private 
methods anywhere in the implementation.

> Sure you can provide private declarations in a class extension, but why would 
> you? To avoid repetition is a virtue, and one of the more important ones at 
> that. 

It may be useful to workaround the afore-mentioned limitation. 

> 
> j o a r

-- Jean-Daniel




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to