I am using the following code to iterate through a plist to find a string
i then want to use the values for the keys – fraction and number
unfortunately something isn’t working and i can’t figure it out
any help will be appreciated
NSString *theNumber = @"0.0075";
BOOL found = NO;
NSUInteger f;
for (f = 0; f < [selectorKeysFractions count]; f++) {
NSString * stringFromArray = [selectorKeysFractions objectAtIndex:f];
if ([theNumber isEqualToString:stringFromArray]) {
found = YES;
break;
}
}
if ( found ) {
// do found
//this line fails with unrecognised selector message
NSLog(@"%@",[[selectorKeysFractions objectAtIndex:f]objectForKey:@"fraction"]);
} else {
// do not found
}
my plist data looks like this
<plist version="1.0">
<dict>
<key>fraction</key>
<string>1/128</string>
<key>number</key>
<string>23.78</string>
</dict>
<dict>
<key>fraction</key>
<string>1/234</string>
<key>number</key>
<string>25</string>
</dict>
</plist>
i am setting up the array like this
NSString *path2 = [[NSBundle mainBundle] pathForResource:@"Fractions" ofType:@"plist"];
pickerData2 =[[NSDictionary alloc]initWithContentsOfFile:path2];
selectorKeysFractions = [[NSArray alloc] initWithArray:[pickerData2 allKeys]];
i am doing something wrong but can’t figure it out
please help
thanks
You send the message “objectForKey” to an object of NSString. You have to request your NSDictionary to get the right entry.
Check this:
This should return your string.