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 Designated Initializers and Convenience Constructors

Ludwing Najera
Ludwing Najera
4,596 Points

BlogPost troubles

I am putting a convenience constructor in my code and when i put it in, the convenience constructor said that blogPostWith title was not declared. then it says that the other method, bp, had a expected expression

BlogPost *bp = [[BlogPost alloc] initWithTitle:@"some title"];
bp.author = @"Author";

BlogPost *bp1 = [BlogPost blogPostWithTitle:@"another title"];
bp1.author = @"Amit";

in my.m file where blogPostWithTitle was declared, i will put the code below

+(id)blogPostWithTitle:(NSString *)title {
       return [[self alloc] initWithTitle:title];
}

help please!

4 Answers

Stone Preston
Stone Preston
42,016 Points

did you add the method headers to your .h file so that they are visible to other classes?

Ludwing Najera
Ludwing Najera
4,596 Points

not that i know of maybe?

Ludwing Najera
Ludwing Najera
4,596 Points

yes, i put method headers on there, i just checked

Michael Keesling
Michael Keesling
4,065 Points

I believe you simply forgot to create an instance of it in the "BlogPost.h" class.
If you only set up blogpost.m to contain the - (id) ______ stuff then you won't have initialized it correctly.

You have to have in BlogPost.h - (id) initWithTitle:(NSString *)title;

and BlogPost.m

  • (id) initWithTitle:(NSString *) title {

    self = [super init]; if (self) { self.title = title;

    } return self; }