Friday, November 6, 2026
HomeiOS Developmentios - Core Knowledge saving Object's relationship to present Object

ios – Core Knowledge saving Object’s relationship to present Object

[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.

enter image description here

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments