What does the Indexed Property of a CoreData attribute do?

I would recommend to read this on indexes: http://en.wikipedia.org/wiki/Index_(database).  Simply put, a database engine creates a new structure which keeps the indexed column (which corresponds to a property) sorted and a link to the corresponding row for each entry (primary key). This allows for faster searches (since search in ordered lists is faster than in … Read more

Core Data: Query objectIDs in a predicate?

A predicate like NSPredicate *predicate = [NSPredicate predicateWithFormat:@”NOT (self IN %@)”, arrayOfExcludedObjects]; where the entity of the fetch request is the entity of objects in the array, should do what you want. This can, of course be combined with other clauses in a single predicate for a fetch request. In general, object comparisons (e.g self … Read more

How to update @FetchRequest, when a related Entity changes in SwiftUI?

I also struggled with this and found a very nice and clean solution: You have to wrap the row in a separate view and use @ObservedObject in that row view on the entity. Here’s my code: WineList: struct WineList: View { @FetchRequest(entity: Wine.entity(), sortDescriptors: [ NSSortDescriptor(keyPath: \Wine.name, ascending: true) ] ) var wines: FetchedResults<Wine> var … Read more

Xcode 8 generates broken NSManagedObject subclasses for iOS 10

I finally got mine to work. Here is what I did. (Flights is one of my entities) I setup the xcdatamodeld as follows And then the entity as Then I used Editor -> Create NSManagedObject Subclass This creates two files for my flights entity Flights+CoreDataProperties.swift Flights+CoreDataClass.swift I renamed Flights+CoreDataClass.swift to Flights.swift Flights.swift is just import … Read more

Core Data: NSPredicate for many-to-many relationship. (“to-many key not allowed here”)

You’re trying to compare a collection (categories.name) to a scalar value (category.name). You need to either use a collection comparator (CONTAINS), or use a predicate modifier (ANY/ALL/SOME, etc). Try using: [NSPredicate predicateWithFormat:@”ANY categories.name =[cd] %@”, category.name]; Or: [NSPredicate predicateWithFormat:@”categories.name CONTAINS[cd] %@”, category.name];