2009-07-02 15 views
3

Ma question est pourquoi il sort les 4 dernières lignes dans le journal (voir ci-dessous) ... ces objets font partie du dictionnaire imprimé plus tôt dans le journal & ne devrait pas être situé à la fin du tableau? Il me manque quelque chose de fondamental ici ... thxEnumerating tableau qui contient un dictionnaire produit une sortie inattendue

NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys: 
    [NSURL URLWithString: @"www.stanford.edu"], 
    @"Stanford University", 
    [NSURL URLWithString: @"www.apple.com"], 
    @"Apple shop", 
    [NSURL URLWithString: @"cs193p.stanford.edu"], 
    @"CS193P course", 
    [NSURL URLWithString: @"itunes.stanford.edu"], 
    @"Stanford on iTunes U", 
    [NSURL URLWithString: @"stanfordshop.com"], 
    @"Stanford Mall", 
    nil]; 

NSMutableArray *myArray = [NSMutableArray arrayWithObjects: 
    [NSString init], 
    [NSURL URLWithString: @"www.stanford.edu"], 
    [NSProcessInfo processInfo], 
    dictionary, 
    [@"Mutable string example" mutableCopy], 
    [@"another mutable string" mutableCopy]]; 

NSEnumerator *enumerator = [myArray objectEnumerator]; 
id object; 

while ((object = [enumerator nextObject])) { 
    NSLog([object description]); 
} 

2009-07-02 09: 35: 12,756 WhatATool [6407: 10b] NSString
2009-07-02 09: 35: 12,756 WhatATool [6407: 10b] www.stanford.edu
2009-07-02 09: 35: 12,757 WhatATool [6407: 10b] <NSProcessInfo: 0x107e20>
2009-07-02 09: 35: 12,758 WhatATool [6407: 10b] {
« Apple boutique "= www.apple.com;
"Cours CS193P" = cs193p.stanford.edu;
"Stanford Mall" = stanfordshop.com;
"Université Stanford" = www.stanford.edu;
"Stanford sur iTunes U" = itunes.stanford.edu;
}
2009-07-02 09: 35: 12,758 WhatATool [6407: 10b] exemple de chaîne Mutable
2009-07-02 09: 35: 12,759 WhatATool [6407: 10b] une autre chaîne mutable
2009-07 -02 09: 35: 12.760 WhatATool [6407: 10b] itunes.stanford.edu
2009-07-02 09: 35: 12.760 WhatATool [6407: 10b] Stanford sur iTunes U
2009-07-02 09:35 : 12,761 WhatATool [6407: 10b] stanfordshop.com
2009-07-02 09: 35: 12,762 WhatATool [6407: 10b] Stanford Mall

Répondre

24

Je pense que vous manquez le nul nécessaire que le dernier argument lorsque vous créez votre NSMutableArray en utilisant la méthode pratique. Est-ce que

NSMutableArray *myArray = [NSMutableArray arrayWithObjects: 
    [NSString init], 
    [NSURL URLWithString: @"www.stanford.edu"], 
    [NSProcessInfo processInfo], 
    dictionary, 
    [@"Mutable string example" mutableCopy], 
    [@"another mutable string" mutableCopy], 
    nil]; 

travail?

+0

merci tas, sauvez-moi un peu de frustration - facile à manquer –

4

Allumez les avertissements (autres drapeaux d'avertissement « -Wall ») et vous obtiendrez:

avertissement: manque sentinelle fonction d'appel

à la fin de votre méthode arrayWithObjects NSMutableArray pour vous dire au sujet de la Manquant.

+0

Je l'aime quand -Wall sauve la journée. Bien qu'il produise souvent des tonnes de spewage qui vient d'être ignoré, il y a des moments où il brille vraiment ... –

+1

"des tonnes de spewage"? Je cours avec Permanelty -Wall et "traite les avertissements comme des erreurs" (ce qui évite les avertissements qui se faufilent lorsque vous faites une construction et que vous ne les revoyez plus). Mon code compile proprement sans avertissements. Je suppose que si vous êtes coincé en utilisant un code tierce qui pourrait être un problème, mais à part ça, il suffit de corriger les avertissements! –