adding/removing objects from an array

Discussion in 'Mac Programming' started by Darkroom, Jun 5, 2008.

  1. Darkroom Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #1
    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?
     
  2. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #2
    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 ;).
     
  3. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #3
    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.
     
  4. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #4
    He mentions it because you can easily miss the array and not check ;).
     

Share This Page