Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
778 views
in Technique[技术] by (71.8m points)

objective c - what's the difference between NSManagedObjectContext reset and rollback?

The documentation says:

- (void)reset

Returns the receiver to its base state.

Discussion

All the receiver's managed objects are “forgotten.” If you use this method, you should ensure that you also discard references to any managed objects fetched using the receiver, since they will be invalid afterwards.


- (void)rollback

Removes everything from the undo stack, discards all insertions and deletions, and restores updated objects to their last committed values.

Discussion

This method does not refetch data from the persistent store or stores.

It seems that after I make some change to my context, calling these two method will do exactly the same thing: discard changes and restore updated objects to their last committed values. So what does -reset actually do?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...