I have a Core Data data model where I have two similar, but not same, entities. I took the common attributes and stuck them in an abstract entity. I marked the abstract entity as a parent entity of the two original entities in my data model.
I can generate NSManagedObject subclasses without issue, and in code, I can manipulate attributes of instances of either child entity and have the app compile fine.
One of the child entities works just fine in runtime. However, when I attempt to mess with entity-only attributes on the other child entity, I get a crash with an
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[KUNLearnedItem setWord:]: unrecognized selector sent to instance 0x7ffec0d08ee0'.
If I turn off the parent/child relationship for the one entity and regenerate NSManagedObject subclasses, I can manipulate the attributes just fine.
Any thoughts? I've been pulling my hair out for days over this.
It was a bug related to finding the entity name in the core data library I was using. I installed and used Mogenerator to generate NSManagedObject subclass files and all is well.
Related
I am trying to add derived attributes, introduced in iOS 13, to an app. The issue arises when creating a new version of the xcdatamodel with two new attributes in Entity A. Each of those attributes is a boolean, and is set as derived and optional. Each references an optional boolean on Entity B. None of the attributes on either entity is set as scalar. For each new derived attribute the derivation is basically a simple, to-one keypath to an object on Entity B. When I add just one of the new attributes - either one - the app functions fine. As soon as I add another attribute, the app crashes on inserting a new object into Entity A. Expanding on this, I find that adding more than one derived attribute at all to any entity is causing a crash upon inserting a new object into that entity.
The error is simply
Thread 1: signal SIGABRT
with no reason given.
This seems like crazy behavior to me. I can't find anyone else having a similar issue. Is this expected behavior for Core Data in iOS 13?
I am trying to add a new entity in NSManagedObjectModel in my NSIncrementalStore Subclass. I am doing this in loadMetadata method but it keeps throwing this exception on the last line. See Code Below
"NSInternalInconsistencyException" Entities for a configuration must already be in the model
Code
var model:AnyObject=(self.persistentStoreCoordinator?.managedObjectModel.copy())!
var newEntity=NSEntityDescription()
newEntity.name="newEntity"
newEntity.managedObjectClassName="newEntity"
var entities=model.entitiesForConfiguration(self.configurationName)
entities?.append(newEntity)
model.setEntities(entities!, forConfiguration: self.configurationName)
You cannot modify a model after it has been added to a persistent store coordinator. The only time you can manipulate the model is just after initialization and before applying it to the NSPersistentStoreCoordinator.
The documentation is unclear about this, but before calling setEntities:forConfiguration: the entities being set must already exist in the managed object model's entities array. This is because this method actually assigns existing entities in the model to a particular configuration.
The solution here is to make a mutable copy of the entities array, add your entities to it if they do not exist, and then set the managed object model's entities array to an immutable copy of the modified array.
After that point you can invoke setEntities:forConfiguration:.
It would be worth filing a radar bug report on this behavior.
I am using coredata to save the server data through web services in my application and I am storing relationships as an object to the entity.
I have many entities e.g "Inspirations" and "Products" and both are related to each other. I have a problem whenever the records are updated in the third entity which is "Filters" then the relations of the entities broke and I cannot apply filters on the entities.
[object addRelatedInspirationsObject:related];
This is how I save relationships. I am not able to figure out why the relations are being broken once the entity is updated which has no direct link with the entity.
One thing more if I fetch and save the data of any one of the entities like "Inspirations" then all the relations start to work again.
Your code should work. Here are 2 things you need to check:
Make sure related is not nil when you call your method.
Make sure you call save on a valid managed object context.
From your question it seems that entities have 1 to many relationship between them. And by the code you supplied, every things should work fine. Just make sure, you are using the Filter object from the relationship like object.filter (or obj1.obj2.filter), not accessing it via a direct NSPredicate on Filter entity and updating it. And if you are using FRC, you might also need to generate a fault against the parent entities, to get your UI updates.
In SimpleTodo, Simperium says
Simperium starting...
Simperium loaded 1 entity definitions
Simperium managing 2 Todo object instances
Simperium found an existing auth token for myemail#myhost.de
Simperium starting network managers...
after init and start.
When starting Simperium in my own app the line saying Simperium managing x MyEntity object instancesis missing. It says Simperium loaded 15 entity definitions, though.
The datamodel of my app is quite complex (hence the 15 entities) and I didn't introduce a SPManagedObject in my datamodel. But I changed all NSManagedObject superclasses to SPManagedObject and added the two attributes ghostData and simperiumKey to all entities.
What can I do to check if all is good? What do I have to do, to make it manage my entities?
We pushed a fix for Entity names tonight that should help with the problem you're having. It should now be possible to specify the ghostData and simperiumKey attributes manually if you prefer complete control over your table structure (as discussed in Inherit from SPManagedObject).
What does Simperium tried to send object changes for nil key mean and how can I debug / fix it?
This will occur if an object doesn't have a simperiumKey. Some things to check:
Does your entity inherit from a parent entity in your model file (usually SPManagedObject) that has the simperiumKey attribute of type String?
Is the class for your entity set to SPManagedObject? Or, if you're using a custom subclass, have you updated the header file for your subclass to inherit from SPManagedObject instead of NSManagedObject?
If you're manually adding the simperiumKey attribute to a model (for example, to micromanage your tables: Inherit from SPManagedObject), you may also need to manually add the simperiumKey and ghostData variables to your custom subclass if you have one.
We'll also improve the log message to give you a better indication of what is happening in this case.