In swift previously, I was able to use a code like this to add new data to my \"TestEntity\" in my data model.
NSManagedObject
was created for my \"TestEnti
working example:
let fr:NSFetchRequest=TestEntity.fetchRequest()
do {
let results=try self.moc!.fetch(fr)
if results.count==0 {
print("no resutls. i need to add something")
let newTestEntity=TestEntity(context: self.moc!)
newTestEntity.testAtt="testovaci text"
do {
try self.moc!.save()
}catch{
}
}else{
print("already some results")
for result in results {
print(result.testAtt!)
}
}
}catch {
print(error)
}
Data model inspector TestEntity Class name needs to be set to TestEntity. Previous strange behaviour seemed to be caused by this value to be blank.