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

Marc Zovighian
Marc Zovighian
1,664 Points

Why id instead os BlogPost?

I still dont quite understand why my initializer and convenience constructor use a return type of id.

How can it be anything else than a blogpost? why is is better to use id?

Also a student pointed out that it was better to use instancetype instead of id. Is that true?

Thanks for the help

PS: is there any way to have Amit or someone double check answers?

1 Answer

Jason Wayne
Jason Wayne
11,688 Points

Id type basically just states that a method returns a reference to that object. It can be ANY type of object.

Instance type states that a method returns a reference to an object of the same type as the class which calls that particular method

I guess I could see why it is better to use instancetype rather than id. Using id would mean you will not get any form of checking at all. With instancetype, you the compiler can check if you are getting the type of object that you are supposed to.