iphone - if else in nsdictionary -
i have dictionary of array:
array3 = [[nsdictionary dictionarywithcontentsoffile:docpath2] retain];
no problem here. have nsstring *temp contains numbers. check whether number exist in dictionary, not each array.
if([array3 valueforkey:temp])
is right? doesn't if loop execute if true?
<dict> <key>123456</key> <array> <string>low</string> <string>high</string> </array> <key>78910</key> <array> <string>low</string> <string>high</string> </array> </dict>
for example temp = 78910, found.
thks in adv
not sure question, i'll give shot.
first, objectforkey:
method use valueforkey:
key-value coding , give strange results should key start @.
then, if objectforkey:
return pointer (i.e. return value not nil
/null
/0
) key exists , has value (which returned). yes, can do:
if ([array3 objectforkey:temp]) { // something, dictionary contain value // key referenced "temp". }
now, if keys strings @"123"
, can of course [array3 objectforkey:@"123"]
. if got integer, need [array3 objectforkey:[nsstring stringwithformat:@"%d", 123]]
.
also note can use nsnumber
or nsvalue
keys. do:
[mymutabledictionary setobject:someobject forkey:[nsnumber numberwithint:123]]; myvalue = [mymutabledictionary objectforkey:[nsnumber numberwithint:123]]; if (myvalue) { // something. }
Comments
Post a Comment