Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,842 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