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! NSArrays and NSMutableArrays in Practice

Is count not a property of the NSArray class and should therefore be referenced as quizArray.count?

Is count not a property of the NSArray class and should therefore be referenced as quizArray.count, rather than through the method [quizScore count]?

I checked Apple's docs and found: "Methods to Override... Any subclass of NSArray must override the primitive instance methods count and objectAtIndex:." What does this mean?

2 Answers

Zachary Betz
Zachary Betz
10,413 Points

To answer your first question, count is not a property of NSArray so it cannot be referenced as quizArray.count. Instead, it is a method, so it must be referenced as [quizArray count].

To answer your second question, any subclass of NSArray must override the count and objectAtIndex methods.

I imagine there are scenarios where subclassing NSArray would be needed -- but most of the time just using the NSArray class will be sufficient.

Hope that helps :)

Thanks Zachary. It makes sense that count is a method rather than a property, but in the Apple NSArray docs it says that it is in fact a property.

@property(readonly) NSUInteger count

Any idea what is going on here?

Zachary Betz
Zachary Betz
10,413 Points

Oops, you're right kavanseggie. After a bit more research, turns out it's a matter of preference whether to use quizArray.count or [quizArray count].

Check out this Stack Overflow article for a more detailed explanation.