problems viewing contents of array

Discussion in 'iOS Programming' started by blue-lion, May 17, 2012.

  1. blue-lion, May 17, 2012
    Last edited by a moderator: May 17, 2012

    blue-lion macrumors member

    Joined:
    Jan 26, 2010
    #1
    hello again, i am experimenting with the addobject method ,and previously i have managed to interrogate the contains of the nsmutablearray within the debugger, but this time although no error or warning message is being displayed i can't seem to do it. The array variable is there, but shows no contents?

    the array is declared as part of a class in the usual way

    with
    Code:
    NSMutableArray *scoreLog;
    
    @property(nonatomic,strong) NSMutableArray *scoreLog;
    in the header



    and in the implementation file



    later in the implementation file , i have the following line

    Code:
    [scoreLog addObject:[NSNumber numberWithInt:10]];
    just after this command i set up a break point and look at the scoreLog
    but there nothing inside it?

    any ideas?
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    No where are you actually creating an NSMutableArray instance and assigning it to the property. All you have declared is a variable to store the instance and that it's a property with synthesized accessors. This does not magically create an array instance assigned to that property.
     
  3. blue-lion thread starter macrumors member

    Joined:
    Jan 26, 2010
    #3
    viewing arrays

    sorry , I'm still a relative newbie…


    whats the difference between creating an instance, and declaring a variable to store an instance?
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    If you don't know that the best thing to do is stop writing code and go and read up on the very basics of programming. Essentially what is the difference between having a space to park a car and actually having a car?
     
  5. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #5
    Declaring a variable:
    Code:
    NSMutableArray *scoreLog;
    Creating an instance (and calling init on it since those tend to go together...)
    Code:
    [[NSMutableArray alloc] init];
    Doing both in one line:
    Code:
    NSMutableArray *scoreLog = [[NSMutableArray alloc] init];
    Methods that create an instance are class methods that return an id or pointer to the instance that was created.

    Class methods are the ones prefixed with a + (rather than a - ) in their declaration.
     
  6. blue-lion thread starter macrumors member

    Joined:
    Jan 26, 2010
  7. blue-lion thread starter macrumors member

    Joined:
    Jan 26, 2010
    #7
    problems viewing contents of array

    sorry, one further thought...

    i assume i don't have to alloc-init on instance variables?, only arbitrary variables not part of any class?
     
  8. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #8
    No object will exist unless you alloc/init it somewhere
     

Share This Page