• 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
clarification regarding properties
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

clarification regarding properties


  • Subject: clarification regarding properties
  • From: WT <email@hidden>
  • Date: Fri, 27 Mar 2009 17:24:00 +0100

Hello all,

I'd like a little clarification, please. If I understand correctly, there *is* a difference between using self.foo and just foo, where foo is a property, right?

foo = whatever

just sets the value of foo to the value of whatever, but

self.foo = whatever

actually calls the method setFoo: with whatever as its argument. This difference is important because the setter method might do some necessary memory management which the simple unqualified assignment never does.

Is my understanding correct?

If it is, this would be a major gotcha for Java developers new to Obj- C. In Java, this.foo = whatever has the exact same effect as foo = whatever when foo is a member variable of some object (except when there's a local variable also named foo but that's a scoping issue, not a semantic one).

Also, this means that it's best *always* to use the qualified assignment for properties, since there's a chance that a property might be changed from assigned to retained or copied (or from nonatomic to "atomic").

Thanks.

Wagner
_______________________________________________

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: clarification regarding properties
      • From: Quincey Morris <email@hidden>
    • Re: clarification regarding properties
      • From: Alexander Spohr <email@hidden>
    • Re: clarification regarding properties
      • From: Nick Zitzmann <email@hidden>
  • Prev by Date: Re: several windows in a NIB ?
  • Next by Date: Re: several windows in a NIB ?
  • Previous by thread: Re: several windows in a NIB ?
  • Next by thread: Re: clarification regarding properties
  • Index(es):
    • Date
    • Thread