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 trialMisha Shaposhnikov
8,718 PointsUsing Custom Class Quiz
In the iOS Track, for the Blog Reader app, under the Achievement Data Modeling, the last quiz is giving me trouble. I can't solve the question that asks to use a convenience constructor. Isn't this the right way?
Song *someSong = [Song songWithSinger: @"James Brown"];
2 Answers
J Andrew Scott
30,626 PointssongWithSinger:
is actually a factory method. It gets called on the class as a whole. Constructors are called on newly allocated instances of the class. I'm guessing the constructor would look something like this:
Song *someSong = [[Song alloc] initWithSinger:@"James Brown"];
Misha Shaposhnikov
8,718 PointsMy original post was correct. A convenience constructor takes care of allocating memory and returning an instance all in one method call. J Andrew Scott's post is called a designed initializer. You still have to call alloc to allocate memory but you can initialize and assign values to an object with the same method call.
As for the quiz, there seems to be a bug with the Treehouse quick-checker. Just remove the space between the colon after songWithSinger and the @ symbol and it should work. like this:
Song *someSong = [Song songWithSinger:@"James Brown"];
Brett Kim
11,576 PointsBrett Kim
11,576 Pointsdidn't work for me...