Skip to content
This repository
Browse code

Updating documentation

  • Loading branch information...
commit b9e35462fd8a2904fb182621a7b8cfb9d9518091 1 parent fdd2b71
Saul Mora casademora authored

Showing 1 changed file with 26 additions and 15 deletions. Show diff stats Hide diff stats

  1. +26 15 README.md
41 README.md
Source Rendered
@@ -14,30 +14,32 @@ Magical Record for Core Data was inspired by the ease of Ruby on Rails' Active R
14 14
15 15 # Installation
16 16
17   -- In your XCode Project, add all the .h and .m files from the Source folder into your project.
18   -- Add *CoreData+MagicalRecord.h* file to your PCH file or your AppDelegate file.
19   -- Start writing code! ... There is no step 3!
  17 +1. In your XCode Project, add all the .h and .m files from the Source folder into your project.
  18 +2. Add *CoreData+MagicalRecord.h* file to your PCH file or your AppDelegate file.
  19 +3. Start writing code! ... There is no step 3!
20 20
21 21 # ARC Support
22 22
23   -As of tag 1.5, ARC is supported. I am not aware of any way to provide a backward compatible solution and still maintain only 1 codebase, so MagicalRecord will be ARC compliant from here on in.
  23 +MagicalRecord will not directly support ARC at this time. However, MagicalRecord will work with ARC enabled, by adding the *-fno-objc-arc* flag to the following files:
  24 +
  25 +* NSManagedObjectContext+MagicalRecord.m
  26 +* NSManagedObject+MagicalDataImport.m
  27 +* MagicalRecordHelpers.m
24 28
25 29 # Usage
26 30
27 31 ## Setting up the Core Data Stack
28 32
29 33 To get started, first, import the header file *CoreData+MagicalRecord.h* in your project's pch file. This will allow a global include of all the required headers.
30   -Next, somewhere in your app's startup, say in the applicationDidFinishLaunching:(UIApplication *) withOptions:(NSDictionary *) method, use one of the following setup calls with the MagicalRecordHelpers class:
  34 +Next, somewhere in your app delegate, in either the applicationDidFinishLaunching:(UIApplication *) withOptions:(NSDictionary *) method, or awakeFromNib, use **one** of the following setup calls with the MagicalRecordHelpers class:
31 35
32 36 + (void) setupCoreDataStack;
33 37 + (void) setupAutoMigratingDefaultCoreDataStack;
34 38 + (void) setupCoreDataStackWithInMemoryStore;
35 39 + (void) setupCoreDataStackWithStoreNamed:(NSString *)storeName;
36 40 + (void) setupCoreDataStackWithAutoMigratingSqliteStoreNamed:(NSString *)storeName;
37   -
38   - - or -
39 41
40   -Simply start creating, fetching and updating objects. A default stack will be created for you automatically if one does not already exist. It's magical :)
  42 +Each call instantiates one of each piece of the Core Data stack, and provides getter and setter methods for these instances. These well known instances to MagicalRecord, and are recognized as "defaults".
41 43
42 44 And, before your app exits, you can use the clean up method:
43 45
@@ -45,7 +47,7 @@ And, before your app exits, you can use the clean up method:
45 47
46 48 ### Default Managed Object Context
47 49
48   -When using Core Data, you will deal with two types of objects the most: NSManagedObject and NSManagedObjectContext. MagicalRecord for Core Data gives you a place for a default NSManagedObjectContext for use within your app. This is great for single threaded apps. If you need to create a new Managed Object Context for use in other threads, based on your single persistent store, use:
  50 +When using Core Data, you will deal with two types of objects the most: *NSManagedObject* and *NSManagedObjectContext*. MagicalRecord for Core Data gives you a place for a default NSManagedObjectContext for use within your app. This is great for single threaded apps. If you need to create a new Managed Object Context for use in other threads, based on your single persistent store, use:
49 51
50 52 NSManagedObjectContext *myNewContext = [NSManagedObjectContext context];
51 53
@@ -53,17 +55,19 @@ When using Core Data, you will deal with two types of objects the most: NSManage
53 55 This default context will be used for all fetch requests, unless otherwise specified in the methods ending with **inContext:**.
54 56 If you want to make *myNewContext* the default for all fetch requests on the main thread:
55 57
  58 +
56 59 [NSManagedObjectContext setDefaultContext:myNewContext];
57 60
58 61
59 62 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.
60 63
61   -**It is recommended that the default context is created and set using the main thread**
  64 +**It is *highly* recommended that the default context is created and set using the main thread**
62 65
63 66 ### Fetching
64 67
65 68 #### Basic Finding
66   -Most methods in the MagicalRecord for Core Data library return an NSArray of results. So, if you have an Entity called Person, related to a Department (as seen in various Apple Core Data documentation), to get all the Person entities from your Persistent Store:
  69 +
  70 +Most methods in MagicalRecord return an NSArray of results. So, if you have an Entity called Person, related to a Department (as seen in various Apple Core Data documentation), to get all the Person entities from your Persistent Store:
67 71
68 72
69 73 NSArray *people = [Person findAll];
@@ -87,7 +91,7 @@ If you want to be more specific with your search, you can send in a predicate:
87 91
88 92 NSArray *people = [Person findAllWithPredicate:peopleFilter];
89 93
90   -Returning an NSFetchRequest
  94 +#### Returning an NSFetchRequest
91 95
92 96 NSPredicate *peopleFilter = [NSPredicate predicateWithFormat:@"Department IN %@", departments];
93 97
@@ -95,7 +99,7 @@ Returning an NSFetchRequest
95 99
96 100 For each of these single line calls, the full stack of NSFetchRequest, NSSortDescriptors and a simple default error handling scheme (ie. logging to the console) is created.
97 101
98   -Customizing the Request
  102 +#### Customizing the Request
99 103
100 104 NSPredicate *peopleFilter = [NSPredicate predicateWithFormat:@"Department IN %@", departments];
101 105
@@ -110,11 +114,18 @@ Customizing the Request
110 114
111 115 You can also perform a count of entities in your Store, that will be performed on the Store
112 116
113   - NSUInteger count = [Person numberOfEntities];
  117 + NSNumber *count = [Person numberOfEntities];
114 118
115 119 Or, if you're looking for a count of entities based on a predicate or some filter:
116 120
117   - NSUInteger count = [Person numberOfEntitiesWithPredicate:...];
  121 + NSNumber *count = [Person numberOfEntitiesWithPredicate:...];
  122 +
  123 +There are also counterpart methods which return NSUInteger rather than NSNumbers:
  124 +
  125 +* countOfEntities
  126 +* countOfEntitiesWithContext:(NSManagedObjectContext *)
  127 +* countOfEntitiesWithPredicate:(NSPredicate *)
  128 +* countOfEntitiesWithPredicate:(NSPredicate *) inContext:(NSManagedObjectContext *)
118 129
119 130 #### Finding from a different context
120 131

0 comments on commit b9e3546

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