Answer the question
In order to leave comments, you need to log in
How to get a list of available fields of the Core data entity?
There is a task to parse the data coming from the server and write them to the entity. The data comes in JSON format, is safely parsed into dictonary and even saved using the entity.setValuesForKeys(dictonary) method. However, there is a small problem. The fact is that the server in the output sometimes adds additional fields that are not in the entity. Why the application crashes...
For example, there is a class:
public class User {
@NSManaged public var id: Int64
@NSManaged public var name: String
}
Answer the question
In order to leave comments, you need to log in
entity description
Pay attention to the properties:
Code example:
for (name, attr) in newManagedObject.entity.attributesByName {
let attrType = attr.attributeType // NSAttributeType enumeration for the property type
let attrClass = attr.attributeValueClassName ?? "unknown"
print(name, "=", newManagedObject.valueForKey(name), "type =", attrClass)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question