How do you update a CoreData entry that has already been saved in Swift?

后端 未结 14 2728
有刺的猬
有刺的猬 2020-11-30 00:55

I\'m not sure what I\'m doing wrong here, but when I save the first time into coredata, it works just fine. When I try to overwrite that, it doesn\'t.

func t         


        
14条回答
  •  忘掉有多难
    2020-11-30 01:46

    You're creating multiple new LoginData objects, but your loadLoginData method is always returning the same object, the first one from the fetch request results.

    You want to keep updating the same object, so you need to change your saveLoginDetails method.

    Instead of creating a new object (which is what insertNewObjectForEntityName) does, use the loadLoginDetails method to get your existing one, and change the property on there.

提交回复
热议问题