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

Jack Crane
2,745 PointsUsing a custom class quiz
Having a spot of bother with these 3 questions
1) Create an instance of the Song with alloc and init Song *popSong = ______________;
2) Create an instance of the Song class with the convenience constructor songWithSinger:(NSString *)s and singer named "James Brown". Song *popSong = ____________;
3) Create an instance of the Song class with the designated initializer initWithSinger:(NSString *)s and singer named "James Brown". Song *popSong = ______________;
If someone could help me out and quickly explain how it works that would be great, gone back over some videos and still struggling :<
Thanks in advance
4 Answers

Thomas Nilsen
14,957 Points1) Song *popSong = [[Song alloc] init];
2) Song *popSong = [Song songWithSinger:@"James Brown"];
3) Song *popSong = [[Song alloc] initWithSinger:@"James Brown"];
Meaning the convenience method would look something like this:
+ (id) songWithSinger:(NSString *)singer{
return [[self alloc] initWithSinger:singer];
}
Designated method:
- (id) initWithSinger:(NSString *)singer{
self = [super init];
if(self){
self.singer = singer;
}
return self;
}

Jack Crane
2,745 PointsI've seen what I've done wrong now... syntax. :@ so anoying lol

Thomas Nilsen
14,957 PointsI usually type the challenges out in Xcode, and then past it in :)

Jack Crane
2,745 PointsI think im going to start doing that aswell, the mistake i was making is that I was writing song instead of Song, little things!

Matthew Simo
5,202 PointsFor some reason this quiz does not accept a space between the ':' & '@'. Which, is valid syntax.. and hasn't been an issue on previous quizzes..
Both of the following SHOULD pass, but only the first actually does.
Song *popSong = [Song songWithSinger:@"James Brown"];
Song *popSong = [Song songWithSinger: @"James Brown"]; // Note the space

Jack Crane
2,745 Points
Amit Bijlani
Treehouse Guest TeacherSorry about that. Our quiz engine is a bit restrictive. It's on our todo list to change these quizzes to code challenges.

Matthew Simo
5,202 PointsUnderstandable, just wanted to post it so that if anyone else was pulling their hair out they could potentially find out why. Thanks for the course, great job Amit!