Tuesday, May 7, 2013

NSDictionary allKeys example ios


allKeys

Returns a new array containing the dictionary’s keys.
- (NSArray *)allKeys
Return Value of [NSDictionary allKeys]
A new array containing the dictionary’s keys, or an empty array if the dictionary has no entries.
Discussion
The order of the elements in the array is not defined.
Example of [NSDictionary allKeys]
NSDictionary *yourDictionary;
NSArray * yourKeys
yourKeys = [yourDictionary allKeys];
Example of [NSDictionary allKeys]
NSArray *sortedKeys = [[dictionary allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];

NSMutableString *myString = [[NSMutableString alloc] init];

for (NSString *key in sortedKeys) {
    [myString appendFormat:@"%@ : %@\n", key, [dictionary objectForKey:key]];
}

self.label.text = myString;