I have an NSMutableDictionary with three key/value pairs.
key1 - person object1 key2 - person object2 key3 - person object3
By comparing a string with the key in the dictionary, I need to retrieve the contents of the person object. How can I do this? Please help me. My code is:
NSArray *keys = [persondict allKeys];
id key;
for(int i= 0; i<[keys count]; ++i)
{ key = [keys objectAtIndex:i];
}
for(id key in persondict){
if ([key isEqual:agentrefattr]){
//how to get the person object here?
[aperson setPhoneNumber:aperson.PhoneNumber];
[aperson setEmailAddress:aperson.EmailAddress];
[aPersonName setGivenName:aPersonName.GivenName];
[aPersonName setSurname:aPersonName.Surname];
[aperson setPersonName:aperson.PersonName];
[self.agentarray insertObject:aperson atIndex:index];
[self.agentnamearray insertObject:aPersonName atIndex:index];
aperson = [agentarray objectAtIndex:index];
aPersonName = [agentnamearray objectAtIndex:index];
NSLog(@"att:%@",agentrefattr);
NSLog(@"Email :%@",aperson.EmailAddress);
NSLog(@"Phone :%@",aperson.PhoneNumber);
NSLog(@"Given Name :%@",aperson.PersonName.GivenName);
NSLog(@"SurName :%@",aperson.PersonName.Surname);
Please help me with some hints. I want to access the properties, GivenName, Surname, etc., in the person object.
The keys in a dictionary are unique. So if
agentrefattris a string representing a key, yuu will only ever have one object in the dictionary with that key, so there is no need for a loop at all. Just do this: