2017-08-23 1 views
-3

int main (int argc, const char * argv []) {{ @autoreleasepoolPourquoi count renvoie-t-il 0 pour le nombre d'objets dans mon tableau alors qu'il devrait y en avoir 3?

NSMutableArray *myMute; 
    NSString *stringOne = @"This is string 1"; 
    NSString *stringTwo = @"This is string 2"; 
    NSString *stringThree = @"This is string 3"; 

    [myMute addObject: stringOne]; 
    [myMute addObject: stringTwo]; 
    [myMute addObject: stringThree]; 

    NSLog(@"There are %li objects in the myMute array", [myMute count]); 


    return 0; 
} 

}

+0

et [vides NSMutableArray] (https://stackoverflow.com/questions/11632308/), [NSMutableArray toujours Emtpy] (https://stackoverflow.com/questions/12892597/), [de la difficulté à ajouter des objets à NSMutableArray] (https://stackoverflow.com/question s/851926 /), [Impossible d'ajouter des éléments à NSMutableArray] (https://stackoverflow.com/questions/7125326/) –

Répondre

-1

Juste allouer tableau que vous créez ensemble zéro, vous devez allouer la mémoire avec une nouvelle ou alloc

NSMutableArray *myMute = [NSMutableArray new]; 

    NSString *stringOne = @"This is string 1"; 
    NSString *stringTwo = @"This is string 2"; 
    NSString *stringThree = @"This is string 3"; 

    [myMute addObject: stringOne]; 
    [myMute addObject: stringTwo]; 
    [myMute addObject: stringThree]; 

    NSLog(@"There are %li objects in the myMute array", [myMute count]); 


    return 0;