Objective-C Language NSDictionary Fast Enumeration

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

NSDictionary can be enumerated using fast enumeration, just like other collection types:

NSDictionary stockSymbolsDictionary = @{
                                     @"AAPL": @"Apple",
                                     @"GOOGL": @"Alphabet",
                                     @"MSFT": @"Microsoft",
                                     @"AMZN": @"Amazon"
                                   };

for (id key in stockSymbolsDictionary)
{
    id value = dictionary[key];
    NSLog(@"Key: %@, Value: %@", key, value);
}

Because NSDictionary is inherently unordered, the order of keys that in the for loop is not guaranteed.



Got any Objective-C Language Question?