• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Private Method?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Private Method?


  • Subject: Re: Private Method?
  • From: Wim Lewis <email@hidden>
  • Date: Mon, 07 Nov 2011 11:08:01 -0800

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@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

References: 
 >Private Method? (From: Bryan Harrison <email@hidden>)

  • Prev by Date: Re: Private Method?
  • Next by Date: Re: ObjectController preventing WindowController from releasing
  • Previous by thread: Re: Private Method?
  • Next by thread: Re: Private Method?
  • Index(es):
    • Date
    • Thread