i have a dictionary of array:
array3 = [[NSDictionary dictionaryWithContentsOfFile:docpath2] retain];
no problem here. now i have
an NSString *temp which contains some numbers.
i would like to check whether this number exist in the dictionary, not each array.
if([array3 valueForKey:temp])
is this right? doesn’t the if loop execute if its 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, i would like it to be found.
thks in adv
Not sure I get your question, but I’ll give it a shot.
First,
objectForKey:is the method to use asvalueForKey:is for Key-Value Coding and will give you strange results should your key start with an @.Then, if
objectForKey:does return a pointer (i.e. the return value is notnil/NULL/0) then the key exists and has a value (which was returned). So yes, you can do:Now, if your keys a strings like
@"123", then you can of course do[array3 objectForKey:@"123"]. But if you got an integer, then you would need to do[array3 objectForKey:[NSString stringWithFormat:@"%d", 123]].Also note that you can also use
NSNumberorNSValueas keys. So you could do: