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 Blog Reader iPhone App Data Modeling Creating a Custom Class: Part 1

hui yi yeh
hui yi yeh
7,199 Points

change the name title to _title in .m file

After we change the name title to _title in BlogPost.m file, shouldn't we also change the name title to _title in BlogPost.h file? Why not?

2 Answers

David Kaneshiro Jr.
David Kaneshiro Jr.
29,247 Points

In the C and Objective C languages, it is not necessary that the parameter names used in the method declarations written in the BlogPost.h file exactly match what's written in the method definition in the BlogPost.m file. This means that Amit could've changed the parameter name of title in the setTitle method definition to lollipop and it would still work. For example:

// This is what I could write as my method declaration in my BlogPost.h

- (void) setTitle: (NSString *) title;


// This is what I could write as my method definition BlogPost.m

- (void) setTitle: (NSString *) lollipop {
   title = lollipop;
}

The above code would still compile and work the same as if the parameter names matched as title.