-
Notifications
You must be signed in to change notification settings - Fork 803
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
. Sincesize
is 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 thecount
of a collection. The expressionsubviews.count
does not return the number of subviews. Instead, it tries to get thecount
property of each subview. The@
symbol tellsNSPredicate
to directly access thecount
of the container. Referring back to the example, the keypathsubviews.@count
will 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.