-
Notifications
You must be signed in to change notification settings - Fork 804
findinstances
Generally, NSPredicate syntax is somewhat guessable and intuitive (relative to popular programming languages). There are two exceptions:
-
When a keypath contains a reserved keyword, it has to be escaped with
#. An example of this is referring to a layer'ssize. Sincesizeis a reserved words inNSPredicate's language, it has to be escaped using#. To get the height of a view, for example:view.layer.bounds.#size.height. -
For collections, keypaths apply to the items inside the collection, not the outer collection itself. To make a key apply to the collection itself, escape the key with
@. An example is referring to thecountof a collection. The expressionsubviews.countdoes not return the number of subviews. Instead, it tries to get thecountproperty of each subview. The@symbol tellsNSPredicateto directly access thecountof the container. Referring back to the example, the keypathsubviews.@countwill return the number of subviews.
For more information on NSPredicate syntax, the "Predicate Programming Guide" has some detail. The list of reserved words is in the "Predicate Format String Syntax" section.