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 Object-Oriented Objective-C Memory, Arrays and Loops, Oh My! Review NSArrays and NSMutableArrays

Daniel Kokin
Daniel Kokin
1,496 Points

Quiz confusion about data types

Question 1: NSArrays and (NSMutableArrays) can hold: correct answer: NSStrings and NSDictionaries wrong answer: All of the above (which includes primitives, and such)

However, in question 4: An individual NSArray (or NSMutableArray) can hold: correct answer: All of the above (which includes: any type of object, any number of elements, the element repeated...

How is this possible if the NSArray cannot hold primitives. Isn't a primitive also an object? Or am getting caught in a trick question that shows I'm confused about scalar data types and objects?

Daniel Kokin
Daniel Kokin
1,496 Points

Sorry about the structure of my sentences. My formatting was changed after I posted the question.

1 Answer

Unfortunately, primitive types are not objects. So int, float, char etc. are scalar C types. They do not have properties or methods linked to them. So that's the reason NSArrays and NSDictionaries cannot hold them. Because they aren't objects.

However, a NSArray can hold multiple copies of the same object, and can hold any number of elements that the memory allows.

Daniel Kokin
Daniel Kokin
1,496 Points

Thank you, Abirbhav. I appreciate the response.