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 trialDaniel Kokin
1,496 PointsQuiz 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?
1 Answer
Abirbhav Goswami
15,450 PointsUnfortunately, 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
1,496 PointsThank you, Abirbhav. I appreciate the response.
Daniel Kokin
1,496 PointsDaniel Kokin
1,496 PointsSorry about the structure of my sentences. My formatting was changed after I posted the question.