Simperium tried to send object changes for nil key - simperium

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.

Related

Remove or Add an attribute to CoreData at runtime programmatically

I have to create and remove attributes based on an api response in Objective C.
For example, Now my api response contains fields "facebook", "whatsapp" and "viber". But in future the reponse can add "youtube". Based on this response, I have to remove all the attributes and values of an entity "Social", and create Four attributes now and set values.
How to do that programmatically? Because the default *.xcdatamodeld file cant help me here, right?
Note: My project is in objective C.
The data model is mutable when the app starts-- you can completely build the model in code, and not use the model editor, for example. But as soon as you load a persistent store file, you must treat the model as fixed. Any changes after loading a persistent store will cause crashes. That means any changes would have to happen before calling either loadPersistentStores(completionHandler:) or addPersistentStore(with:completionHandler:).
Alexander's suggestion of optional attributes is a good one. If you need the model to be more dynamic, you would need to create a new related entity which would store the service name plus whatever information you need to save about the service. If you did this, your Social entity would have a to-many relationship to a new entity called something like Service. Service would have a string property called name that would have values like twitter, facebook, youtube, etc. It would also have whatever other attributes you need to save about the service.
You can create all 4 fields in advance and just make them optional and fill them depending on the server response. But you cannot add new attributes in runtime. Your *.xcdatamodeld file compiles into *.momd and it contains all the data to create tables in the DB since Core Data by default works with SQLite under the hood and it's a relational database management system.
To make attributes optional you should check that.
And then newly created objects contain nil as default values of object properties. So, in your case your "youtube" property of Social object will be just nil.

"NSInternalInconsistencyException" Entities for a configuration must already be in the model

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.

Core Data - Fetched Property with bitmasks and abstract entities

(Data models renamed to preserve anonymity. :D )
So, I have a situation where on a Thing, whose configuration is defined by its own special object, though that object can be one of 2 class types.
I would like to be able to do Fetch Requests on this model by asking if the Thing's Configuration is of a certain known subclass, and if so, does it have a few specific flags set in its bitmask. If this is true, I define this as being "not special". Therefore, if it also has the other type of subclass as it's Configuration, it is also "not special".
My questions are these:
Have I got my syntax right? (In my app I get faults)
Why does it want to return an NSArray? (I thought its traversing a to-one relationship on a single object. How would I therefore interpret this NSArray?)
I should add that I only know Core Data via MagicalRecord more or less. And I use mogenerator too.

Discrepancies Between Core Data Editor and NSManagedObjectSublcass

How are discrepancies between the Core Data Editor and the custom NSManagedObject subclass handled by Xcode?
For instance, let's say in the editor I have and Entity called Person with attributes firstName and age. I then create an NSManagedObject subclass of Person from the editor and in the header of the subclass I add the attribute lastName but I don't update the editor with this new attribute.
Depends somewhat on exactly how you define the property, but usually it will be treated like a transient property, so its value will not be set when the object is retrieved from the store unless you write some custom code to set it, nor will Core Data make any attempt to save it to the store. Also you won't be able to use the property in any fetch or sort predicate that results in core data generating sqlite SQL calls.

Core data parent entity generated NSManagedObject subclass

I have in my model a parent entity, "List" and a child entity (subentity) named "UserList" which is just a type of list. "UserList" has no attributes or relationships of its own, it inherits everything from List. List has a to-many relationship to ListItem.
I ask XCode 4.2 to generate the NSManagedObject subclasses.
For List it generates what I'd expect including,
- (void)insertObject:(NSManagedObject *)value inListItemsAtIndex:(NSUInteger)idx;
- (void)removeObjectFromListItemsAtIndex:(NSUInteger)idx;
...
However the generated "UserList" class does not declare any methods which would be ok if it was declared as a subclass of "List" but thats not what it generated.
#interface UserList : NSManagedObject
#end
Is UserList really a subclass of List? Can I just change the header? Or is something more complex going on?
A couple of things to check. First, make sure you have given both List and UserList entities a class name, and then make sure UserList has declared List as its parent entity.
The generator is finicky. If you have not specifically assigned a class name in the model GUI, it generates them on the fly. Unfortunately, it means that, depending on the order in which they are generated, some may not be generated with the right information (imaging UserList being generated first... if you did not specifically give List a class name, it only knows to use NSManagedObject).
By convention, I always specifically assign class names in the model GUI. I've not seen this happen when I specifically assign a class to each entity (under where you give the entity its name), but I guess it may happen.
Try to re-generate the class files. It may just get generated correctly this time.
EDIT
Clarification after comment...
NOTE: Unfortunately, Xcode is being very consistent in this matter. If you do not explicitly give class names to entities, others that reference it will be generated with "wrong" class names.
I suggest following one of following options for your work flow.
Always assign class names in the GUI for each entity.
Always generate the classes twice when you generate for the first time.
Use mogenerator https://github.com/rentzsch/mogenerator#readme instead of the Xcode class generator.

Resources