I have a score property on my Core Data Entity Student. So, when adding a newStudent object, its related one-to-one score property must have a value, different from nil, to be saved.
User can change that score value later on another views, but for object creation itself I do need a default value. And I can't find a working way to set a default one.
My Student class:
extension Student {
@nonobjc public class func fetchRequest() -> NSFetchRequest<Student> {
return NSFetchRequest<Student>(entityName: "Student")
}
//Another properties...
@NSManaged public var evaluation: Score?
}
My Score class:
extension Score {
@nonobjc public class func fetchRequest() -> NSFetchRequest<Score> {
return NSFetchRequest<Score>(entityName: "Score")
}
//Another properties...
@NSManaged public var depiction: String?
@NSManaged public var student: Student?
}
I suposse I have to create any type of singleton, and static var not to be created-and-saved each time I add a student, but just to pass it to the ViewContext to be saved as a part of newStudent saving. I hope I have explained myself...
I'm trying to add something like this to my Students+CoreDataMethods:
extension Score {
static var defaultScore: Score {
self.defaultScore.depiction = "None"
}
...
}
But it throws errors like "Function call causes an infinite recursion", and "Missing return in getter expected to return 'Score'"".
I don't find a correct approach to deal with it. Any ideas? Thanks!