0

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?

JAL
  • 41,701
  • 23
  • 172
  • 300
Vitya Shurapov
  • 2,200
  • 2
  • 27
  • 32
  • 1
    See [this answer](http://stackoverflow.com/a/11597537/5389870). – xoudini Jan 17 '17 at 16:16
  • 5
    `[cd]` is case and diacritic insensitive, everything else is described in [Predicate Programming Guide](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html) – vadian Jan 17 '17 at 16:21

1 Answers1

3

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

Ashley Mills
  • 50,474
  • 16
  • 129
  • 160