Learning Core Data for iOS with Swift: A Hands-On Guide to Building Core Data Applications by Tim Roadley
Author:Tim Roadley [Roadley, Tim]
Language: eng
Format: azw3, pdf
Publisher: Pearson Education
Published: 2015-12-07T05:00:00+00:00
* * *
A compound predicate is a set of NSPredicate objects used together. When a compound predicate is created it needs to be of a certain type, either AND, OR, or NOT. The chosen type specifies how the predicates that make up the compound predicate should be used together. The predicateForAttributes function supports all compound predicate types. The following list explains how to create compound predicates:
To create a compound AND predicate, pass .AndPredicateType as the type. This specifies that all the criteria of all subpredicates must be met. In SQL terms, this is similar to the WHERE clause in the statement SELECT * FROM MyTable WHERE FirstName = 'Tim' AND LastName = 'Roadley'.
To create a compound OR predicate, pass .OrPredicateType as the type. This specifies that criteria of at least one of the subpredicates must be met. In SQL terms, this is similar to the WHERE clause in the statement SELECT * FROM MyTable WHERE FirstName = 'Tim' OR LastName = 'Roadley'.
To create a compound NOT predicate, pass .NotPredicateType as the type. This specifies that none of the criteria of any subpredicates are allowed to be met. In SQL terms, this is similar to the WHERE clause in the statement SELECT * FROM MyTable WHERE FirstName NOT IN ('Tim') AND LastName NOT IN ('Roadley').
In Listing 8.9 the compound predicate is built from an array of predicates. The array of predicates is drawn from the given dictionary of attribute values. This dictionary is iterated and for each attribute found a predicate is created and put in the predicates array.
Update Groceries as follows to add the predicateForAttributes function:
1. Add the code from Listing 8.9 to the bottom of CDOperation.swift before the last curly brace.
Before inserting a managed object from XML, a check is needed against the target context to ensure that the proposed object does not already exist. To achieve this, a fetch is performed on the target context with a predicate specific to the unique attribute values. The code involved is shown in Listing 8.10.
Listing 8.10 Unique Object with Attribute Values (CDOperation.swift)
Click here to view code image
Download
Learning Core Data for iOS with Swift: A Hands-On Guide to Building Core Data Applications by Tim Roadley.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(6532)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6409)
Kotlin in Action by Dmitry Jemerov(5062)
Odoo 15 Development Essentials - Fifth Edition by Daniel Reis & Greg Mader(3323)
Odoo 15 Development Essentials by Daniel Reis(2811)
React Native - Building Mobile Apps with JavaScript by Novick Vladimir(2526)
Learning Angular - Second Edition by Christoffer Noring(2355)
Pride and Prejudice by Jane Austen(2346)
Mobile Forensics Cookbook by Igor Mikhaylov(2014)
Computers For Seniors For Dummies by Nancy C. Muir(1995)
Bulletproof Android: Practical Advice for Building Secure Apps (Developer's Library) by Godfrey Nolan(1868)
Android Development with Kotlin by Marcin Moskala & Igor Wojda(1794)
Building Android UIs with Custom Views by Raimon Ràfols Montané(1786)
1936941139 (N) by Bob Rosenthal(1731)
Building Progressive Web Apps: Bringing the Power of Native to the Browser by Ater Tal(1722)
Hands-On Internet of Things with MQTT by Tim Pulver(1704)
Android App Development by Franceschi Hervé J.;(1700)
Ember.js in Action by Joachim Haagen Skeie(1686)
Hands-On Design Patterns with React Native by Mateusz Grzesiukiewicz(1652)
