Thursday, May 9, 2013

NSDictionary getObjects example ios


getObjects :andKeys:

Returns by reference C arrays of the keys and values in the dictionary.
- (void)getObjects:(id __unsafe_unretained [])objects andKeys:(id __unsafe_unretained[])keys
Parameters
objects
Upon return, contains a C array of the values in the dictionary.
keys
Upon return, contains a C array of the keys in the dictionary.
Discussion of [NSDictionary getObjects]
The elements in the returned arrays are ordered such that the first element in objects is the value for the first key in keys and so on.
Example of [NSDictionary getObjects]
NSDictionary *myDictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"1", @"A", @"2", @"B", nil];

NSInteger count = [myDictionary count];
id objects[count];
id keys[count];
[myDictionary getObjects:objects andKeys:keys];

for (int i = 0; i < count; i++) {
  id obj = objects[i];
  id key = keys[i];
  NSLog(@"%@ -> %@", obj, key);
}
Example of [NSDictionary getObjects]
NSDictionary *myDictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"1", @"A", @"2", @"B", nil];

NSInteger count = [myDictionary count];
id __unsafe_unretained objects[count];
id __unsafe_unretained keys[count];
[myDictionary getObjects:objects andKeys:keys];

for (int i = 0; i < count; i++) {
  id obj = objects[i];
  id key = keys[i];
  NSLog(@"%@ -> %@", obj, key);
}