Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

zippyfly

macrumors regular
Original poster
Mar 22, 2008
141
0
Hi folks.

So I've come across mention that methods not declared in @interface and written up in @implementation can still be called?

Of what use is this?

It seems such methods are not actually @private to the object. I can't see this being a mistake on the part of the designers so I'm wondering why this is allowed?
 

Sydde

macrumors 68030
Aug 17, 2009
2,552
7,050
IOKWARDI
Most often you see this used for overrides (methods prototyped by a superclass, like -init or -mouseDown), for protocol implementation (like NSCoding or datasource, implicitly prototyped via the protocol conformance declaration) and for delegate methods. Occaisionally you might see non-prototyped methods that are only used within the implementation, which the programmer might do in order to hide the methods, but this is a generally discouraged practice.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
But of course! (Smacks forehead. Mine, not yours. ;-)

I recommend to set up your projects so that all compiler warnings are treated as errors, then make use of unknown selector a warning. (Especially useful when you write @selector(thismethod) instead of @selector(thismethod: ) )

I tend to have something like

@interface myclass (privatebits)
...
@end

in my implementation files for internally used methods so that these methods are not even visible in the header file.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.