NSArray Question

Discussion in 'iOS Programming' started by jjardim, Jan 9, 2010.

  1. jjardim macrumors newbie

    Joined:
    Mar 19, 2008
    #1
    Trying to work with NSMutable array and having trouble -

    here is part of the .h file

    @class AllAnswers;

    @interface StartDeck : UIViewController {

    // Class Object to keep track of the past
    AllAnswers *allanswers;
    NSMutableArray *allanswersArray;

    .....

    In the .m file

    allanswers = [[AllAnswers alloc] initWithFirst:temp1 initWithSecond:temp2 initWithThird:temp3 initWithFourth:temp4 initWithTop:randomTopValue initWithBottom:randomBottomValue];

    [allanswersArray addObject:allanswers];
    NSLog(@"temp1 - %i", temp1);
    NSLog(@"Array - %i",[[self allanswersArray] temp1]);
    NSLog(@"Array Count %i", allanswersArray.count);


    The Log Shows
    2010-01-09 11:50:22.464 FlashCards[10024:207] temp1 - 18
    2010-01-09 11:50:22.465 FlashCards[10024:207] Array - 0
    (gdb) continue
    Current language: auto; currently objective-c
    2010-01-09 11:50:25.625 FlashCards[10024:207] Array Count 0

    I would think that the Log in Array - would print out the temp1 variable and the Array Count would return 1.
    I set a break point and it seems nothing is in the array set.

    Any Help would be appreciated.

    Thanks,
    Jardim
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    What do you think this is doing?

    Code:
    [[self allanswersArray] temp1]
    
    Also NSArray count returns a NSUInteger. See the U? It means unsigned. Look at the NSLog format specifiers and think very carefully about whether %i is really what you want...
     

Share This Page