Reputation: 226
I'm new to the great framework Magical Record.
When do I have to give a context to a MR method?
Example:
// with context
NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];
CheckinTypes *checkinType = [CheckinTypes MR_createInContext:localContext];
// without context
CheckinTypes *checkinType1 = [CheckinTypes MR_createEntity];
What's the difference between those two possibilities?
Upvotes: 0
Views: 137
Reputation: 69667
The basic rule of thumb is:
However, the real answer is more complex than that. Using Core Data in general requires managing your contexts for your particular scenario. One common scenario is a settings screen where settings are saved in Core Data. By using a new context, and making your changes in that context, you can then simply toss the context (ie. not save) it to remove any temporary changes the user has not committed to.
Also, please note that MR_contextForCurrentThread has been deprecated and will be removed in an upcoming release of MagicalRecord. Using this method will lead to occasional, hard to track down crashes.
Upvotes: 1