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

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -