• 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: Trying to understand -- please help...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trying to understand -- please help...


  • Subject: Re: Trying to understand -- please help...
  • From: "Shawn Erickson" <email@hidden>
  • Date: Wed, 21 May 2008 12:24:48 -0700

On Wed, May 21, 2008 at 12:14 PM, Vijay Malhan <email@hidden> wrote:
> Thanks for the pointers to the documentation. This is sample snippet from
> the documentation.
>
> @implementation MyClass
>
> + (void)initialize
>
> {
>
>     if ( self == [MyClass class] ) {
>
>         /* put initialization code here */
>
>     }
>
> }
>
> If I'm not wrong "self" equivalent of "this" which points to an instance
> var.

self (and this in C++) do not point to an instance var, to are an
implicit / hidden parameter to methods that give you a reference to
the object your method is operating "under the context of".

> And it is initialized in - init (instance)method.

Nope. Again self is an implicit method parameter.

> And if it fails to initialize, it's nil.

If you are in a class or instance method self is valid (otherwise you
wouldn't be in the method) and it will remain valid unless you do
something to invalidate it (set self to something else or otherwise
cause the object self is referencing to be deallocated, etc.).

> So does "self" even exist when + initialize is called.

In the case of class methods in objective-c (those with + in front)
self is a reference the class object.

<http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_2_section_4.html#//apple_ref/doc/uid/TP30001163-CH11-TPXREF115>
<http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_8_section_5.html>

-Shawn
_______________________________________________

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: 
 >Trying to understand -- please help... (From: Peter Hudson <email@hidden>)
 >Re: Trying to understand -- please help... (From: "I. Savant" <email@hidden>)
 >Re: Trying to understand -- please help... (From: "I. Savant" <email@hidden>)
 >Re: Trying to understand -- please help... (From: Vijay Malhan <email@hidden>)
 >Re: Trying to understand -- please help... (From: "Shawn Erickson" <email@hidden>)
 >Re: Trying to understand -- please help... (From: "Vijay Malhan" <email@hidden>)

  • Prev by Date: Re: Cocoa Training....
  • Next by Date: Re: Cocoa et al as HCI usability problem
  • Previous by thread: Re: Trying to understand -- please help...
  • Next by thread: Re: Trying to understand -- please help...
  • Index(es):
    • Date
    • Thread