what's the difference between NSManagedObjectContext reset and rollback?

前端 未结 2 428
清歌不尽
清歌不尽 2021-01-01 15:19

The documentation says:

- (void)reset

Returns the receiver to its base state.

Discussion

All the receiver\'s man

相关标签:
2条回答
  • 2021-01-01 15:59

    The key part is in the quote

    All the receiver's managed objects are “forgotten”.

    - (void)reset; will give you a clean NSManagedObjectContext with no objects in it and as the docs state any NSManagedObject's you have around should be discarded as they are no longer valid.

    - (void)rollback will just restore the NSManagedObject's to their persisted values

    0 讨论(0)
  • 2021-01-01 16:01

    -reset is different than -rollback in that it invalidates any NSManagedObjects that have been fetched from the context. Attempting to use those objects can be expected to throw an exception. However -rollback simply discards unsaved changes.

    0 讨论(0)
提交回复
热议问题