I'm having a wired problem with core data. With Swift3 in iOS 10 I get the managed object context each time I am fetching or storing data with
func getContext () -> NSManagedObjectContext {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
return appDelegate.persistentContainer.viewContext
}
In my app I have two entities 'User' and 'Ledger'. I want to assign a ledger to a user, but a user can have multiple ledgers. Therefore, I have a UserTableView where I can display the users and a UserViewController class, where I create a user. The same I have for ledger. When creating a ledger I get also a list of all users from which I select one and which should assigned to the ledger and vice versa.
When saving like aforementioned, I get the error
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable type of value for to-one relationship: property = "user"; desired type = User; given type = User;
My data model looks as follows: Data Model
Any help is highly appreciated:)