Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Update default context documentation

  • Loading branch information...
commit 56faeb93db3ae4db095fd8c1c27b6a02c64711b8 1 parent 5778191
@tonyarnold tonyarnold authored
Showing with 18 additions and 13 deletions.
  1. +18 −13 Docs/
31 Docs/
@@ -1,26 +1,31 @@
### Default Managed Object Context
-When using Core Data, you will deal with two types of objects the most: *NSManagedObject* and *NSManagedObjectContext*. MagicalRecord provides a single place for a default NSManagedObjectContext for use within your app. This is great for single threaded apps. You can easily get to this default context by calling:
+When working with Core Data, you will regularly deal with two main objects: `NSManagedObject` and `NSManagedObjectContext`.
- [NSManagedObjectContext MR_defaultContext];
+MagicalRecord provides a simple class method to retrieve a default `NSManagedObjectContext` that can be used throughout your app. This context operates on the main thread, and is great for simple, single-threaded apps.
-This context will be used if a find or request method (described below) does not specify a specific context using the **inContext:** method overload.
+To access the default context, call:
-If you need to create a new Managed Object Context for use in other threads, based on the default persistent store that was creating using one of the setup methods, use:
+NSManagedObjectContext *defaultContext = [NSManagedObjectContext MR_defaultContext];
- NSManagedObjectContext *myNewContext = [NSManagedObjectContext MR_context];
-This will use the same object model and persistent store, but create an entirely new context for use with threads other than the main thread.
+This context will be used throughout MagicalRecord in any method that uses a context, but does not provde a specific managed object context parameter.
-And, if you want to make *myNewContext* the default for all fetch requests on the main thread:
+If you need to create a new managed object context for use in non-main threads, use the following method:
- [NSManagedObjectContext MR_setDefaultContext:myNewContext];
+NSManagedObjectContext *myNewContext = [NSManagedObjectContext MR_newContext];
+This will create a new managed object context which has the same object model and persistent store as the default context, but is safe for use on another thread.
-MagicalRecord also has a helper method to hold on to a Managed Object Context in a thread's threadDictionary. This lets you access the correct NSManagedObjectContext instance no matter which thread you're calling from. This methods is:
+If you'd like to make your `myNewContext` instance the default for all fetch requests, use the following class method:
- [NSManagedObjectContext MR_contextForCurrentThread];
+[NSManagedObjectContext MR_setDefaultContext:myNewContext];
-**It is *highly* recommended that the default context is created and set using the main thread**
+> **NOTE:** It is *highly* recommended that the default context is created and set on the main thread using a managed object context with a concurrency type of `NSMainQueueConcurrencyType`.

0 comments on commit 56faeb9

Please sign in to comment.
Something went wrong with that request. Please try again.