I have an ShoppingItem Entity(attributes: name, id, unit, qty, description) and another entity ShoppingList(attributes: listDate, listName) and a relationship property : items which is many-to-many relationship. The use case is : _The items that are selected by the user have to be updated to the list on the particular date. let myList = GroceryList(context: CoreDataManager.shared.viewContext) myList.name = One more List myList.madeOn = Date() 1. myList.mutableSetValue(forKey: groceryItems).add(selectedGroceryItems) CoreDataManager.shared.save() selectedGroceryItems is of type struct ItemEntityViewModel { let groceryItem: GroceryItem var itemEntityid: NSManagedObjectID { return groceryItem.objectID } var id: UUID { return groceryItem.id ?? UUID() } var name: String { return groceryItem.name ?? } var category: String { return groceryItem.category ?? Not available } var unit: String? { return groceryItem.unit ?? } var qty: Double? { return Double(groceryItem.qty) } } line 1 throws exception a
3
0
570