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

Misha Shaposhnikov
Misha Shaposhnikov
8,718 Points

Using 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

songWithSinger: 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"];
Brett Kim
Brett Kim
11,576 Points

didn't work for me...

Misha Shaposhnikov
Misha Shaposhnikov
8,718 Points

My 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"];