Predicates in Core Data
Database programming is all about filtering and sorting tables linked to each other. According to the book Core Data , «Core Data is Apple’s object graph management and persistency framework for iOS, OS X, watchOS, and tvOS.» In a sense, predicates are an object version of the WHERE clause in SQL. Just like NSFetchRequest represent the FROM clause in SQL. I never have had problems with WHERE and FROM in SQL, but the predicate format strings in Core Data has been quite a struggle for me. I don’t think the struggle is only my fault. Predicates should clearly be thought, at least to me, as a method of writing WHERE clauses. Here is some notes from tutplus’ Core Data and Swift: Relationships and More Fetching : let predicate = NSPredicate(format: "%K == %@", "last", "Doe") The predicate format string uses %K (K stands for Key) for the property name and %@ for the value. let predicate = NSPredicate(format: "%K >= %i", &qu