Question

This is my first question, but I don't found the answer.

I develop my app in obj-c for iOS platform, I initialize a NSPredicate object in this mode:

NSPredicate *predicate = [NSPredicate predicateWithFormat: @"%@ IN (%@)", uniquePropertyKey, valuesWithDupes];

where uniquePropertyKey is a NSString with name property and valuesWithDupes is a NSArray with objects.

If uniquePropertyKey value is NAME in predicate I have something as "NAME" in {"1", "n"} but I want NAME in {"1", "n"}, why in predicate concatenate strings format add quotes (") at my value?

Était-ce utile?

La solution

The problem here is you are using the dynamic value assigned to the predicate directly with NSSString stringWithFormat and using %@ as the substitution for the dynamic replacement. For the key portion if you make it %K, this will work fine. So, you predicate would be,

NSPredicate *predicate = [NSPredicate predicateWithFormat: @"%K IN (%@)", uniquePropertyKey, valuesWithDupes];

Autres conseils

I have used predicate in my Project like for filter array by category using predicate

    NSString *selectedCategory = activity.user_id;

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"user_id == %@", selectedCategory];

    NSArray *filteredArray = [self.array_selectedActivities filteredArrayUsingPredicate:predicate];

This works for me!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top