Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Simple iPhone App (iOS7) Refactoring into a Model Creating a Custom Class

is there a different between self.quotes and _quotes?

If i have a property in .h file called NSArray quotes. Then in .m file I can access it as self.quotes. Is it the same as saying _quotes. thanks

3 Answers

The reason that is happening is because

_quotes = @"hi how are you" means you are accessing the instance variable and assigning it that string

NSLog(@"%@", self.quotes) means you are accessing the property

If you want the exact specifics I would recommend reading up on "differences between objective c properties and instance variables"

here is a good link: http://stackoverflow.com/questions/843632/is-there-a-difference-between-an-instance-variable-and-a-property-in-objecti

if you need any more help, just ask !


with self.quotes you access the property

with _quotes you access the class instance variable

but i tried _quotes=@"hi how are you"; and NSLog("%@",self.quotes); it was the same

so if i call self.quotes from main - it will call quotes properties getter. if i call a xyz function from main which calls self.quotes in it.. i will get a value that is set for that object in main. if i call _quotes from main .. I cant call it lol.

printing function is in my quotes class

-(void) printing{ NSLog(@" %@",self.quotes); NSLog(@" %@",_quotes); }

in main () i havent set a value for object.quotes. when i call object.printing-- it gives me null for self.quotes but gives me a value for _quotes.. So i understand both are different but still i dont get the exact logic.

DOes it mean that _quotes is a class variable.. it has one value irrespective of what object is calling it. and self.quotes is object specific?