Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

Graves Robber
($1.99)

African Adventure
($0.99)

iTazer
($0.99)

ArtStudio
($3.99)

Pigs Vs Wolves
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 05-05-2009, 10:56 PM   #2 (permalink)
smasher
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,541
Default

Quote:
Originally Posted by jj0b View Post
Trying to understand when it is needed to prepend object names with self.

Sometimes I am able to reference objects that I have initialized without adding self. and other times my code won't work without adding it.

Can someone explain when I should definitely use the self. reference and when it is not needed?
Whenever you use self.blah or someObject.blah, you are using a "property". Properties are an easy way to call certain methods to get and set the value of a variable inside the class (an instance variable.)

In other words, when you say self.blah = true, it's shorthand for [self setBlah:true]. You either need to write the setBlah method yourself, or use @synthesize to get the compiler to write them for you. The setBlah method may copy the object you give it, or retain it, or simply assign it, depending on the settings you chose for the property.

When you simply say blah=true, you are not using the property, and you are not calling the setBlah method. You are simply changing the value of the variable, with no retain or object copy or any other tricks.

If you look up "properties" in your favorite book or reference you'll find out more.
__________________
smasher is offline   Reply With Quote
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 23,681
Threads: 38,445
Posts: 168,923
Top Poster: smasher (2,541)
Welcome to our newest member, kai
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:23 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.