• 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: Jean-Daniel Dupas <email@hidden>
  • Date: Mon, 07 Nov 2011 10:10:23 +0100

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

  • Follow-Ups:
    • Re: Private Method?
      • From: Kyle Sluder <email@hidden>
References: 
 >Private Method? (From: Bryan Harrison <email@hidden>)
 >Re: Private Method? (From: Joar Wingfors <email@hidden>)

  • Prev by Date: What is the right way to move a UIDocument to a new URL?
  • Next by Date: Re: Any success with SMLoginItemSetEnabled?
  • Previous by thread: Re: Private Method?
  • Next by thread: Re: Private Method?
  • Index(es):
    • Date
    • Thread