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

Why do you need to alloc and init objects before using them?

Why is it important and when would you do it?

2 Answers

Using alloc and init method is a must when you create an instance of an Object. An object is different than primitive data types such as int, float, bool. An object storage is allocated in the heap (the memory address in a computer), when you call alloc the compiler automatically allocate the storage of the object in the RAM and give you back the pointer to refer to the object in the heap. Using init is making sure that your object successfully inherit all the superclass property and method as long as you don't change the self = [super init] method in your object init instance method

Got it now,I needed to review it. :P