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!
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

Adam Berkowitz
2,673 PointsBlog Reader Question re Designated Initializers/Convenience Constructors/Custom Class
So I just finished watching the "Creating a Custom Class" video for the blog reader project and I'm confused by part of it. In the previous video we made the designated initializer and convenience constructor for title. Then, in the Custom Class video, Amit uses those to write
'''objectiveC for (NSDictionary *bpDictionary in blogPostsArray) { BlogPost *blogPost = [BlogPost blogPostWithTitle:[bpDictionary objectForKey:@"title"]]; blogPost.author = [bpDictionary objectForKey:@"author"]; [self.blogPosts addObject:blogPost]; } ''' How come we didn't create a designated initializer and convenience constructor for "author" as well as "title"? It seems strange to me to use two different ways to accomplish this. I understand that you can't really write
'''objectiveC BlogPost *blogPost = [BlogPost blogPostWithTitle:[bpDictionary objectForKey:@"title"]]; BlogPost *blogPost = [BlogPost blogPostWithAuthor:[bpDictionary objectForKey:@"author"]]; '''
because the instance variable *blogPost can't be used twice in this way. But is there a way to combine them into one line? What am I missing here? Thanks.

Stone Preston
42,016 Pointsthe marks are back ticks `
not apostrophes '
. the back tick on my keyboard is next to the 1 key. its the same key as the ~

Adam Berkowitz
2,673 Pointsthank you! I was driving myself crazy trying to figure that out.
3 Answers

Stone Preston
42,016 Pointsyou could easily create a convenience constructor blogPostWithTitle:(NSString *)title andAuthor:(NSString *)author
if you wanted to. I think amit was just using the different ways to show you the multiple ways of doing it.

Adam Berkowitz
2,673 PointsI see. I tried creating multiple convenience constructors, but what you're showing me seems to be a longer one. This is like how some methods have multiple places to put in information right?

Stone Preston
42,016 Pointsyes. it has multiple arguments. Methods can have more than one argument. So you pass in two strings to it, the title and the author, and it uses them somewhere in the body of the method.

Adam Berkowitz
2,673 PointsOk. I think I'm beginning to understand more. My programming background is in Max/MSP which is for data and audio work. Usually we would create an object like [cycle~] (which is for waveforms) and then pass it arguments for frequency and amplitude. Same kind of idea here.
Adam Berkowitz
2,673 PointsAdam Berkowitz
2,673 PointsAlso - I can't figure out how to properly format this code using the ''' marks. If someone could help me out I'd appreciate it.