Swift: how to filter master data

I use the following code to retrieve all the data in a category.

let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate let managedContext = appDelegate.managedObjectContext! let fetchRequest = NSFetchRequest(entityName:"category") let fetchedResults = managedContext.executeFetchRequest(fetchRequest, error: &error) as [NSManagedObject]? 

How can I give only categories where "type" is equal to "products"?

+5
source share
1 answer

To β€œfilter” results in Core Data, use NSPredicate as follows:

 let filter = "products" let predicate = NSPredicate(format: "type = %@", filter) fetchRequest.predicate = predicate 
+21
source

Source: https://habr.com/ru/post/1214283/


All Articles