I have an NSArray of UISwitches. I have separately an NSDictionary whose keys are NSNumbers, and whose objects are BOOL values in the form of NSString objects. What I would like to do is iterate through the NSArray of UISwitches, check to see if the tag value is one of the keys inside the NSDictionary, and if a match is found, then set the enabled property of the UISwitch to the key's corresponding object (after converting it to a BOOL from an NSString).
My code is as follows:
for (int i=0; i<[self.switchCollection count]; i++) {
UISwitch *mySwitch = (UISwitch *)[self.switchCollection objectAtIndex:i];
if (tireSwitch.tag == //this has to match the key at index i) {
BOOL enabledValue = [[self.myDictionary objectForKey:[NSNumber numberWithInt://this is the key that is pulled from the line above]] boolValue];
mySwitch.enabled = enabledValue;
}
}
Your code doesn't look right. How about this:
(Edited to use fast enumeration (for...in loop syntax)
That's assuming I understand what you're trying to do...