Enumerating a Dictionary

Program 15.18 illustrates how a dictionary can be defined with initial key-value pairs using the dictionaryWithObjectsAndKeys: method. An immutable dictionary is created, and the program also shows how a fast enumeration loop can be used to retrieve each element from a dictionary one key at a time. Unlike array objects, dictionary objects are not ordered, so the first key-object pair placed in a dictionary might not be the first key extracted when the dictionary is enumerated.

Program 15.18

#import <Foundation/Foundation.h>int main (int argc, char * argv[]){   @autoreleasepool {      NSDictionary *glossary =       [NSDictionary dictionaryWithObjectsAndKeys:        @"A class defined so other ...

Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.