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 with Objective-C Creating a Data Model Finishing Up Our Model

self.funFactLable.text= self.factBook.randomFact; vs self.funFactLable.text= [self.factBook randomFact]; @7:06

Im assuming that self.funFactLable.text= [self.factBook randomFact]; is just the objective-c way to do things but I like the dot notation feel of self.funFactLable.text= self.factBook.randomFact;

I found an interesting debate here: http://qualitycoding.org/dot-notation/

It seems to get mixed reviews and clearly the video used: [self.factBook randomFact]; So moving forward should I just abandon my love of dot notation in objective-c land or is this just a case of whats your favorite ice cream flavor?

*I try to guess before he codes things thats how this question came about if anyone even cares lol

1 Answer

Michael Hulet
Michael Hulet
47,913 Points

I share your love of dot notation, but in Objective-C, I only use dot notation whenever the value I'm trying to access is a @property of its associated class. For example:

@interface FactBook : NSObject
//In my opinion, this should be accessed with dot syntax
@property (strong, nonatomic) NSString *topFact;
//In my opinion, this should never be accessed with dot syntax
-(NSString *)randomfact;
@end

I believe that's what dot notation was introduced to do, so that is what I use it for

you are wise beyond your years young Obi-Wan Kenobi