I have an NSArray
with NSDictionaries
. One of the dictionaries keys in one of the arrays contains a value. I want to retrieve the NSDictionary
with that value.
My array:
Array: (
{
DisplayName = "level";
InternalName = "Number 2";
NumberValue = 1;
},
{
DisplayName = "PurchaseAmount";
InternalName = "Number 1";
NumberValue = 3500;
}
)
So, I would like to get the dictionary which contains DisplayName
set to PurchaseAmount
(case insensitive).
How can I accomplish that?
The following solved my problem:
NSArray *filtered = [promotions filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(DisplayName == %@)", @"PurchaseAmount"]];
NSDictionary *item = [filtered objectAtIndex:0];
Thnx to user Nate for his comment on my question!
LIKE[cd] will also do it
NSArray *filtered = [data filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(DisplayName LIKE[cd] %@)", @"purchaseAmount"]];
returned
<NSArray>(
{
DisplayName = PurchaseAmount;
InternaName = "Number 1";
NumberValue = 3500;
}
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With