I am revolving around with a small issue in iPhone while playing around Array and Dictionary. I have and product dictionary with the following data
name = Product;
options = (
{
code = code1;
name = "product AAA";
},
{
code = code1;
name = "product BBB";
},
{
code = "code2";
name = "product BBB";
},
{
code = "code3";
name = "product CCC";
},
{
code = "code3";
name = "product DDD";
},
{
code = code4;
name = "product EEE";
},
{
code = code4;
name = "product FFF";
}
);
Also i have an array of matching products
matchingProducts
{
"product BBB",
"product CCC",
"product DDD"
)
Now, all i want to do is i want to remove from products dictionary comparing to matchingProducts array. how can i do it.
Note: I cannot use key to remove objects as per my business rules. I have issue as i have names are repeated but i have to get the final result dictionary as shown below. Is it possible.
name = Product;
options = (
{
code = code1;
name = "product AAA";
},
{
code = code1;
name = "product BBB";
},
{
code = code4;
name = "product EEE";
},
{
code = code4;
name = "product FFF";
}
);
Please, reply me back if my question is not clear.
I have fixed the similar issue in java using the below code
for (int j = 0; j < matchingProducts.size(); j++) {
String product = ((Product) matchingProducts.elementAt(i)).name;
for (int i = 0; i <Product.size(); i++) {
String productName = ((Product) Product.elementAt(i)).name;
if (product.equals(productName)) {
Product.removeElementAt(i);
break;
}
}
}
}
// resultant now has what you wanted. Use it.