I have seen many of the answers but didn't get my answer. So that's why I decide to post a question. If anybody can find the helpful link or answer will be helpful. Here is my array of dictionary:
<__NSArrayM 0x283ba04e0>(
{
failvalues = (
"Check 1"
);
fieldname = "Check 3";
fieldvalue = (
"Check 1",
"Check 2"
);
showtype = mandatory;
tagvalue = 0;
},
{
failvalues = (
Fail
);
fieldname = "Dropdown 3";
fieldvalue = (
Fail
);
showtype = mandatory;
tagvalue = 1;
},
{
failvalues = (
"Check 1",
"Check 4"
);
fieldname = "Check 4";
fieldvalue = (
"Check 1",
"Check 2"
);
showtype = mandatory;
tagvalue = 2;
})
So I want to check if the fieldvalue contains failvalues or not. Below is the code which I have tried but it doesn't seem to work:
for (int i = 0; i< [arrFields count]; i++) {
if ([[[arrFields objectAtIndex:i]objectForKey:@"failvalues"] isKindOfClass:[NSArray class]]) {
if (![[[[arrFields objectAtIndex:i] objectForKey:@"failvalues"] objectAtIndex:0] isEqualToString:@""]) {
NSLog(@"Field Values %@",[[arrFields objectAtIndex:i]objectForKey:@"fieldvalue"]);
NSArray *failValues = [[arrFields objectAtIndex:i] objectForKey:@"failvalues"];
for (int j = 0; j < [failValues count]; j++) {
if ([failValues containsObject:[[arrFields objectAtIndex:i]objectForKey:@"fieldvalue"]]) {
NSLog(@"Contains %@",[[arrFields objectAtIndex:i]objectForKey:@"fieldvalue"]);
} else {
NSLog(@"No fail values");
}
}
} else {
NSLog(@"No Fail Fields");
}
} else {
NSLog(@"Not an array");
}
}
EDIT:
This one I have tried but how to break both the loops
for (int i = 0; i< [arrFields count]; i++) {
NSArray *fieldValues = [[arrFields objectAtIndex:i]objectForKey:@"fieldvalue"];
NSArray *failValues = [[arrFields objectAtIndex:i] objectForKey:@"failvalues"];
if (![[[[arrFields objectAtIndex:i] objectForKey:@"failvalues"] objectAtIndex:0] isEqualToString:@""]) {
//NSLog(@"Field Values %@",[[arrFields objectAtIndex:i]objectForKey:@"fieldvalue"]);
for(NSString *value in fieldValues){
if ([failValues containsObject:value]) {
NSLog(@"Contains %@",value);
scanStatus = TRUE;
return;
}
}
} else {
NSLog(@"No Fail Fields");
}
}
Thanks in advance!