I little confuse in NSMutableDictionary retrieving Key and Value checking for that i did this code.
NSMutableDictionary *testDictionary=[NSMutableDictionary dictionary];
// NSMutableDictionary *testDictionary=[[NSMutableDictionary alloc]init];
[testDictionary setObject:@"Muhammed Musthafa" forKey:@"10005"];
[testDictionary setObject:@"Lubaba p" forKey:@"10006"];
[testDictionary setObject:@"Sahala Banu" forKey:@"10007"];
[testDictionary setObject:@"Vishnu k" forKey:@"10008"];
[testDictionary setObject:@"Shabeer PP" forKey:@"10009"];
[testDictionary setObject:@"Sabeehath " forKey:@"10010"];
[testDictionary setObject:@"Anusha GS" forKey:@"10011"];
[testDictionary setObject:@"JINI KS" forKey:@"10012"];
[testDictionary setObject:@"Athulya T" forKey:@"10013"];
[testDictionary setObject:@"Midhun KS" forKey:@"10014"];
for(NSString *kk in testDictionary)
{
NSString *fName;
if(kk==@"10006")
{
fName=[testDictionary objectForKey:kk];
}
if(kk==@"10007")
{
fName=[testDictionary objectForKey:kk];
}
if(kk==@"10013")
{
fName=[testDictionary objectForKey:kk];
}
NSLog(@"KEY=====%@ and Value====%@",kk,fName);
}
The out put value :
2011-11-17 10:49:37.054 ArchiveData[2539:207] KEY=====10013 and Value====
2011-11-17 10:49:37.055 ArchiveData[2539:207] KEY=====10006 and Value====
2011-11-17 10:49:37.056 ArchiveData[2539:207] KEY=====10008 and Value====
2011-11-17 10:49:37.056 ArchiveData[2539:207] KEY=====10010 and Value====
2011-11-17 10:49:37.057 ArchiveData[2539:207] KEY=====10012 and Value====
2011-11-17 10:49:37.057 ArchiveData[2539:207] KEY=====10014 and Value====
2011-11-17 10:49:37.058 ArchiveData[2539:207] KEY=====10005 and Value====
2011-11-17 10:49:37.059 ArchiveData[2539:207] KEY=====10007 and Value====
2011-11-17 10:49:37.060 ArchiveData[2539:207] KEY=====10009 and Value====
2011-11-17 10:49:37.061 ArchiveData[2539:207] KEY=====10011 and Value====
-
why this three {(kk==@”10006″) if(kk==@”10007″) if(kk==@”10013″)} if state ment return false?
-
There is any other method for checking id key like this?
-
I saw the same type of coding working fine in some other coding,So this is depending any other configuration?
-
how can i check particular key==@”some Key value”?
code:
output for your code.
it working fine.
After 10007 you dont have condition for for 10009 and 10011. so the fName value is not changed for that.
When you use the == operator, you are comparing pointer values. This will only work when the objects you are comparing are exactly the same object, at the same memory address.