[ad_1]
How do I save a Todo merchandise and set its relationship to an present Class if one already exists? I understand how to create a brand new Class and set its relationship to the brand new Todo already as proven under. I am doing this inside a type.
Class is ready to have many Todos.
let category2 = Class(context: viewContext)
category2.id = UUID()
category2.title = "Enjoyable"
let todo = Todo(context: viewContext)
todo.title = "Hi"
todo.dueDate = Date.now
todo.relationship = category2
strive? viewContext.save()
//todo.relationship = create a brand new Class if one does not exist, if it does exist, choose that as the connection. If no class, then do nothing
I’ve been following this answer right here https://www.youtube.com/watch?v=y1oWprQqLJY&t=483s and it has the identical subject the place a brand new “Origin” is created every time the button is pressed.
[ad_2]

