On 6 Nov 2011, at 2:10 PM, 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?

It's analogous to having a C function that isn't 'static' but also isn't 
declared in a header. Other files don't know it exists, but they can still 
invoke it.

It could be an override of a superclass's method, a private method--- ObjC 
doesn't have 'static' or other access qualifiers for methods, so this is as 
private as it gets--- or sloppy/old code, or it could be a method that callers 
know about through some other route. Perhaps it's declared in a (formal or 
informal) protocol the class conforms to, dynamically looked up (via 
NSSelectorFromString() or key-value-coding), invoked by means of a SEL passed 
to another piece of code (less common now that we have blocks, but a common 
technique for Cocoa callbacks), etc.

> If the former, how does this technique compare with the trick of putting an…
> 
> @interface someClass ()
> - (type) somePrivateMethod;
> @end

As Brad Cox and Joar Wingfors said, that allows you to forward-declare the 
methods that are only used within your implementation (and it's generally good 
practice, IMHO), but unless I'm forgetting something it doesn't change the 
behavior/semantics/accessibility of the method it declares.

(Footnote: Come to think of it, methods that take or return anything other than 
objects *really* should be declared, much like C functions that take or return 
anything other than ints: you can often get away without the declaration, but 
your code will break someday when you least expect it.)


_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to