Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
i'm currenty reading Cocoa Programming for Mac OS X (3rd edition) and i have a question about page 44 (if you have the book you can see).

Hillegass writes that when an object in added or removed from an array, the index of the array shifts automatically. great! but then he says that runtime errors will occur if the index is greater than the number of elements in the array, or if the number of elements surpasses the index.

so my question is if we add or remove elements from an array, are we responsible to change the index count of the array so not to receive runtime errors? also, if this is the case, wouldn't it have been better for Objective-C if the automation of shifting the index also addressed the automation of changing the index count?
 

Eraserhead

macrumors G4
Nov 3, 2005
10,434
12,250
UK
so my question is if we add or remove elements from an array, are we responsible to change the index count of the array so not to receive runtime errors?

No, it'll be done automatically.

EDIT: To be honest I can't imagine any language where it wouldn't be handled automatically actually, probably even FORTRAN ;).
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
No, it'll be done automatically.

oh ok... strange... i wonder why he felt that he needed to state that runtime errors will occur if the index is greater than the number of elements in the array, or if the number of elements surpasses the index, especially in this section of the chapter where he's discussing how arrays are changed automatically. anyway, thanks for answering Eraserhead.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.