Enumerating array which contains a dictionary produces unexpected output

enumeration, nsarray, nsdictionary, objective-c

Solution

I think you're missing the nil necessary as the last argument when you create your NSMutableArray using the convenience method. Does

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

work?

Problem

My question is why does it output the last 4 lines in the log(see below)...those objects are part of the dictionary printed earlier in the log & should not be located at the end of the array? I am missing something fundamental here... thx ``` 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 shop" = www.apple.com; "CS193P course" = cs193p.stanford.edu; "Stanford Mall" = stanfordshop.com; "Stanford University" = www.stanford.edu; "Stanford on iTunes U" = itunes.stanford.edu; } 2009-07-02 09:35:12.758 WhatATool[6407:10b] Mutable string example 2009-07-02 09:35:12.759 WhatATool[6407:10b] another mutable string 2009-07-02 09:35:12.760 WhatATool[6407:10b] itunes.stanford.edu 2009-07-02 09:35:12.760 WhatATool[6407:10b] Stanford on 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

Original source