Posts

Post not yet marked as solved
3 Replies
Hey! I've had the same exact problem causing my app to crash. The reason of it was because my relationship property (in your case "Item") was nil at the stage of fetch. Try inserting object with type "Item" to model context before inserting Attribute object. Also, there is no need to call "save()" on a Model Context if you have autosave enabled. (it is by default). Data is saved and UI is refreshed right after inserting an object to modelContext. For example: let item1 = Item(name: "Z", order: 0) self.modelContext.insert(item1) self.modelContext.insert(Attribute(item: item1, name: "\(item1.name).0", order: 0)) self.modelContext.insert(Attribute(item: item1, name: "\(item1.name).1", order: 1)) self.modelContext.insert(Attribute(item: item1, name: "\(item1.name).2", order: 2))