Search code examples
iosswiftcore-datanspredicate

Substituting values in NSPredicate format


I've been trying to figure out the different format for substituting in NSPredicate. I'm aware "%@" is string, but what if we are looking for values like Double, Float,CGFloat, etc. I did see "%i", I'm assuming its a substitute for integer but am not completely sure.


Solution

  • Based on official docs, you can use printf format specifiers for other value types (but by the rest of the text I assume in most cases you will be good with %@):

    The format string supports printf-style format specifiers such as %x (see Formatting String Objects). Two important format specifiers are %@ and %K.

    %@ is a var arg substitution for an object value—often a string, number, or date.

    %K is a var arg substitution for a key path.