Vitya Shurapov
Vitya Shurapov

Reputation: 2318

Who can explain this NSPredicate syntax

I have this predicate:

let searchPredicate = NSPredicate(format: "SELF LIKE[cd] %@", searchString)

which I'm using for filtering array and finding the needed string.

Could you explain what this argument "SELF LIKE[cd] %@" means?

Upvotes: 0

Views: 1054

Answers (1)

Ashley Mills
Ashley Mills

Reputation: 53231

To start with, NSPredicate(format:) is like String(format:), so the %@ is replaced with the contents of searchString.

[cd] means case and diacritic insensitive - so john Jonés would match John Jones

LIKE is used to match with a wildcard (* = 0 or more chars, ? = 1 character). so LIKE Joh* would match with John Jones

Upvotes: 4

Related Questions