• 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: self
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: self


  • Subject: Re: self
  • From: Andy Lee <email@hidden>
  • Date: Wed, 8 Jun 2005 11:35:22 -0400

On Jun 8, 2005, at 10:59 AM, Theodore H. Smith wrote:
Am I right in thinking that self is a local (stack based) variable?

It is an implicit argument to every method, so yes it is local (i.e., its scope is the method) and yes it is stack-based. Technically you can treat it like any other method argument, including setting it to whatever value you want. You should almost never do this outside of an init method, because it can make your code confusing and error- prone to have "self" not be the original receiver of the method. Some people feel init methods are a special case because of their unique semantics -- hence this idiom:


- (id)init {
    if ((self = [super init]))
    {
        // ...
    }

    return self;
}

for example the code:

-(id) init {
    self = [self initSpecial];
    return self;
}

should alter everything in exactly the same way as:

-(id) init {
    return [self initSpecial];
}

Yes, those two code examples have identical effects.

--Andy

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >self (From: "Theodore H. Smith" <email@hidden>)

  • Prev by Date: Re: self
  • Next by Date: Re: self
  • Previous by thread: Re: self
  • Next by thread: Re: self
  • Index(es):
    • Date
    • Thread