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

NSPredicate case-insensitive matching on to-many relationship

If I understand you correctly, you want your predicate to be true whenever any keywords name matches the search string. For this you need to test with the ANY keyword like this: [NSPredicate predicateWithFormat:@”ANY keywords.name CONTAINS[c] %@”, …]; This will search the keywords and return true if any of those keywords name contains your search … 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

Xcode – error: pathspec ‘…’ did not match any file(s) known to git

The problem is, indeed, the changing of a filename’s case. For me this was because of my Macbook/OSX. Apparently Windows has the same ‘thing’. Cause: git isn’t able to recognise a change from ‘filename’ to ‘FileName’. Here’s a list of solutions for anyone stumbling upon this. All the solutions should be run at the project … Read more

How can I check what is stored in my Core Data Database?

Here is my solution(works on iOS 9): I use an automator/bash script that open the database in sqllitebrowser. the script finds the latest installed app in the simulator. Instructions: Install DB Browser for SQLite (http://sqlitebrowser.org/) Create new workflow in Apple Automator. Drag “Run Shell script block” and paste this code: cd ~/Library/Developer/CoreSimulator/Devices/ cd `ls -t … Read more

CoreData + iCloud + Cascade Delete – how to handle?

From experience, listening to notifications other than NSManagedObjectContextDidSaveNotification is a big mess and can lead to relying on properties not yet updated. The detail view controller should listen to NSManagedObjectContextDidSaveNotification notifications, which are thrown after cascade is applied. You can then check by several means if the current object is valid or not (you can … Read more

How to store an image in core data

You can store images in Core Data using the Binary Data attribute type. However you should be aware of a few things: Always convert your UIImage to a portable data format like png or jpg For example: NSData *imageData = UIImagePNGRepresentation(image); Enable “Allows external storage” on this attribute Core Data will move the data to … Read more

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