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 Self-Destructing Message iPhone App Retrieving and Viewing Data from Parse.com Retrieving Data from Parse.com

Why don't we allocate and initialize NSArray property messages?

In CameraViewController we have a property recipients. And we allocated and initialized it in the viewDidLoad method. In the InboxViewController we have messages property which we haven't allocated. Why in one case we have to alloc and init property and no in another case? I think it depends on how we than use property. We used recipients for adding objects to it. And we assign objects to the messages. Is differnce in this? When we assign it autoomatically allocates and initializes?

3 Answers

Rashii Henry
Rashii Henry
16,433 Points

hey Igor, I didn't check the video. From what I'm thinking off the top of my head is that the 'messages' property isn't allocated yet simply because you have to retrieve that data from parse. You would want to allocate memory and initialize it once you have that data.

Hi Rashil! Thank you for response. Once we got data from Parse (self.messages = objects;) we haven't allocated the property. Does it mean that allocation performs automatically when we assigning 'objects' from Parse to our property? I want to understand how it works under the hood.

Rashii Henry
Rashii Henry
16,433 Points

I understand. When you're using findObjectsInBackgroundWithBlock

one of the parameters for that method call is the objects(that you're finding from parse)

now you have this array. which is good for holding objects. so within that block you tell your objects to assign themselves into the array by saying something as simple as: array = objects;

Now that it's allocated(because you referenced the name in the implementation) && also (initial)ized because the objects are now in it..

Now anywhere within the implementation after the array has been initialized you can use that data to display it in your application.

But yes you're correct. it didn't happen automatically, it happened because you're the awesome person who typed that line of code to allocate and initialize it!