Tuesday, March 15, 2022

NSPredicate example and how to use them

 https://academy.realm.io/posts/nspredicate-cheatsheet/

Format string summary

@"attributeName == %@"

object’s attributeName value is equal to value passed in

@"%K == %@"

pass a string variable to %K, it will be represented as a keypath, then check if it’s value is equal to value passed in

@"%name IN $NAME_LIST"

templated for predicate, checks if the value of key name is in $NAME_LIST. Uses predicateWithSubstitutionVariables

@"'name' IN $NAME_LIST"

checks if the constant value ‘name’ is in $NAME_LIST. Uses predicateWithSubstitutionVariables

[NSPredicate predicateWithFormat: @"title == %@", @"minecraft"]