Completely Unrelated Error Using Coredata

Completely unrelated error using coredata

Try this:

Go to targets -> Build Settings -> Swift Compiler - Code Generation -> Objective C Bridging Header and Double click on it and do this:

Sample Image

Hope this will help you.

Casting from 'NSPersistentStoreResult' to unrelated type 'Entity' always fails

Use executeFetchRequest method of NSManagedObjectContext when performing a NSFetchRequest.

Edit Swift 3: For Swift 3, use:

let result = try managedContext.fetch(fetchRequest)

Duplicate files in DerivedData folder using CoreData generator

I get this in Xcode 8.1
For me following steps solved the issue. Please note that order matters.

1) Create entity in Core Data model.

2) Under class section, make settings as on following image.

Module: Current Product Name

Codegen: Manual/None

3) Generate your NSManagedObject subclass.

Sample Image

CoreData fails to initialise a managed object when accessed through UserNotification custom action

One more idea: Since you get an initializer error, it seems to me that the object whose id you transfer via the notification is not yet initialized when you try to save it.

In this link I found the following:

object(with:) throws an exception if no record can be found for the
object identifier it receives. For example, if the application deleted
the record corresponding with the object identifier, Core Data is
unable to hand your application the corresponding record. The result
is an exception.

The existingObject(with:) method behaves in a similar
fashion. The main difference is that the method throws an error if it
cannot fetch the managed object corresponding to the object
identifier.

So I suggest to replace in getAssociatedObject(id: String) the call to object(with: moid) by existingObject(with: moid). If this throws an error, you know that the related object does not yet or no longer exist.

If this is allowed by your app, you had to initialize it by the designated initialiser

init(entity entity: NSEntityDescription, insertIntoManagedObjectContext context: NSManagedObjectContext?)  

before you try to store it.

EDIT:

In this answer, you can find more suggestions how to debug your core data handling.

CoreData: warning: Unable to load class named 'Task' for entity 'Task'. Class not found, using default NSManagedObject instead

This may be a simulator error (Sometimes if you change the name of the core data file, or if you move your code around, the simulator data gets confused).
Try going to the simulator and doing Simulator->Reset Content and Settings
This will restart the simulator wiped clean.

Core Data lightweight migration slow even in trivial cases?

I think if you want to use the migration mechanism you are out of luck. Core Data will indeed copy all the data to a new store, and that can take considerable time.

One possible solution could be to create a second, separate store to contain the unrelated entity.

This adds more complexity and is clearly a trade-off but could be feasible. You will have to weigh if it is worth the trouble.

Core Data: Store cannot hold instances of entity (Cocoa Error: 134020)

Okay, I discovered what the problem was.

In the code before what I posted, I used RestKit's seeder object to seed my database from a local json file, and then I continued to add objects after it ran. But it doesn't actually commit the objects to the object store until you call finalizeSeedingAndExit.

Calling that function to seed the first part of my data, then commenting out the seeder and running again, fixed this strange, strange, error.



Related Topics



Leave a reply



Submit