Objective c - Core Data saving approach

前端 未结 3 1280
伪装坚强ぢ
伪装坚强ぢ 2021-01-28 12:38

I have some NSManagedObject subclass in my app, and I\'m trying to understand when and how to save changes.
I will try to explain myself, for example class

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-28 13:12

    The data will not be saved to the persistent store until you call save. So, it depends on what you want in your app. If you want it to be able to recover the last value it ever had, then you should save after each modification.

    Easy change is to just save after making modifications.

    You could do something a bit more fancy, like only save after some set amount of time, so many changes are grouped together... and catch any event that will put your app in the background and then save...

    But, that's what UIManagedDocument does automatically for you, so you could just use that instead.

提交回复
热议问题