How to use NSPredicate for Key-Path values

Using NSPredicate for an array is pretty straight forward using filterArrayUsingPredicate :.

How is this done for key values? So I have an array of objects (in this case, objects of the same type). Each object has an instance variable called a name. According to the documentation, it is said that it performs the following actions:

NSPredicate *predicate = [NSPredicate predicateWithFormat:
   @"ANY employees.firstName like 'Matthew'"];

Is this also used in filterArrayUsingPredicate? What if I have an array of People objects? Does this mean that I will use:

NSArray *allPeopleObjects; // pre-populated
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY people.name like 'Foo'"];
NSArray *matching = [allPeopleObjects filteredArrayUsingPredicate:predicate];

The documentation in this section is a bit missing.

Can I also use a predicate against a single Person object? Something like Person.name contains [cd] 'Foo'? How will this be done?

+3
1

, . NSPredicate . Person, valueForKeyPath: NSPredicate? .

0

Source: https://habr.com/ru/post/1745344/


All Articles