0
Hi, I was wondering how do I save an Entity in core data programmatically.
I tried the following procedure:
Passing parameter
MatchCoreData().createEntity(name: "Partidas123")
Func creating the Entity (I believe it is missing save in the core)
public func createEntity(name: String)
{
// Create the entity
var entities = Array<NSEntityDescription>();
let model = NSManagedObjectModel()
let entity = NSEntityDescription()
if entities.count == 0
{
entity.name = name
entity.managedObjectClassName = String(describing: Match.self)
entities.append(entity)
model.entities = [entity]
saveContext()
}
for item in entities
{
if (item.name?.contains(name))!
{
}else
{
entity.name = name
entity.managedObjectClassName = String(describing: Match.self)
model.entities = [item]
saveContext()
}
}
}