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];

Multiple NSEntityDescriptions Claim NSManagedObject Subclass

Post-automatic-caching This should not happen anymore with NSPersistent[CloudKit]Container(name: String), since it seems to cache the model automatically now (Swift 5.1, Xcode11, iOS13/MacOS10.15). Pre-automatic-caching NSPersistentContainer/NSPersistentCloudKitContainer does have two constructors: init(name: String) init(name: String, managedObjectModel model: NSManagedObjectModel) The first is just a convenience initializer calling the second with a model loaded from disk. The trouble is that … Read more

How can I tell whether an `NSManagedObject` has been deleted?

Checking the context of the managed object seems to work: if (managedObject.managedObjectContext == nil) { // Assume that the managed object has been deleted. } From Apple’s documentation on managedObjectContext … This method may return nil if the receiver has been deleted from its context. If the receiver is a fault, calling this method does … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)