Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/3.0 #1

Merged
merged 158 commits into from
May 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
158 commits
Select commit Hold shift + click to select a range
3ba1cb3
Added autoreleasepool around statements in saveWithBlock calls
casademora Feb 16, 2014
513dab4
Merge branch 'release/3.0' of https://github.com/magicalpanda/Magical…
casademora Feb 16, 2014
4130f4c
update expecta
casademora Feb 16, 2014
cf59cb0
Log no stack context error on release builds
casademora Feb 24, 2014
baf6472
Merge branch 'release/3.0' of https://github.com/magicalpanda/Magical…
casademora Feb 24, 2014
b3c96df
update specta
casademora Feb 24, 2014
06c648a
Remove code signing from Project settings
casademora Feb 27, 2014
a42a62a
Switch Expecta submodule back to mainline, as my patches there have b…
tonyarnold Mar 24, 2014
cc6f2b2
Use new MagicalRecordStack defaultStack in tests
tonyarnold Mar 24, 2014
3742cff
Remove all tests and test targets
tonyarnold Mar 24, 2014
17dffeb
Add checks for NSBooleanAttributeType and NSStringAttributeType in th…
tonyarnold Mar 25, 2014
e3d5305
Always import if no `-(BOOL)shouldImport<#Attribute#>:(id)data` metho…
tonyarnold Mar 25, 2014
fd294e6
Make creation/deletion methods on NSManagedObject more consistent
tonyarnold Mar 25, 2014
740dcd2
Rename `+ MR_defaultURLForStoreName:` and `+ MR_urlForStoreName:` to
tonyarnold Mar 25, 2014
b57a572
Adds `options` dictionary to all of the NSPersistentStore creation me…
tonyarnold Mar 25, 2014
f4683e9
Adds `MR_isEntityDeleted` to the NSManagedObject+MagicalRecord category
tonyarnold Mar 25, 2014
7258d17
Conversion of dates on import should assume GMT, not the user's curre…
tonyarnold Mar 25, 2014
467013a
Remove commented out code
tonyarnold Mar 25, 2014
c285ce7
Formatting and method ordering
tonyarnold Mar 25, 2014
cce8a62
Add method to delete a persistent store at a provided URL, along with…
tonyarnold Mar 25, 2014
4d7048e
Tests!
tonyarnold Mar 25, 2014
576ed47
Reorganise project files so that no build related artefacts are store…
tonyarnold Mar 25, 2014
b63cb0d
Setup Travis CI
tonyarnold Mar 25, 2014
ec257fc
Remove MR_SHORTHAND support
tonyarnold Mar 25, 2014
3143b50
Update Podspec to exclude UIKit categories from OS X, and add myself …
tonyarnold Mar 25, 2014
3f6c17a
Add MRDeprecated() for marking methods as deprecated
tonyarnold Mar 25, 2014
cb31b4a
Provide deprecated versions of the shorthand methods
tonyarnold Mar 25, 2014
b592663
Remove commented out ARC check — the project is set to compile with ARC
tonyarnold Mar 25, 2014
c17fc73
Initial changelog for 3.0
tonyarnold Mar 25, 2014
e45631b
Shorten the length of the testSynchronousSaveActionDoesNotAssignTempo…
tonyarnold Mar 25, 2014
34bf1f4
Fix broken shorthand methods
tonyarnold Mar 25, 2014
ff5bd4e
Add support for importing UNIX timestamps to
tonyarnold Mar 25, 2014
b59b8f8
Check the error status from obtainPermanentIDs in the save tests
tonyarnold Mar 25, 2014
3f29533
Remove bogus remapping of description to MR_description
tonyarnold Mar 27, 2014
97a4bdf
Fixed data import on wrong object class for related objects — based o…
tonyarnold Apr 1, 2014
0651fad
When importing, if no primary key is defined for an entity always do …
tonyarnold Apr 2, 2014
960454c
Fix relationship data import key lookup not seeing more than one `map…
tonyarnold Apr 3, 2014
a9de27a
Add an AppKit-style version double instead of the unmaintainable earl…
tonyarnold Apr 8, 2014
ee1eb4e
Add aggregate operations that support grouping by a keypath
tonyarnold Apr 8, 2014
8f1b1a7
Update fetching documentation
tonyarnold Apr 8, 2014
eede208
Prefix import functions with MR_ to avoid conflicts
tonyarnold Apr 8, 2014
1d7635e
Removing old and busted iCloud support in favor of new and awesomer i…
casademora Apr 8, 2014
f73d3b8
Merge branch 'release/3.0' into features/3.0
tonyarnold Apr 8, 2014
e20764b
Merge pull request #713 from magicalpanda/features/3.0
tonyarnold Apr 8, 2014
f4fd596
Remove iCloud methods from shorthand file
tonyarnold Apr 8, 2014
03c1d81
Set required SDK to iOS SDK 7.0 and OS X SDK 10.9. Bump library compa…
tonyarnold Apr 8, 2014
0f99c34
Restore MR_fetchController:… method to public header
tonyarnold Apr 8, 2014
fcd3ec4
Change import from `#import "CoreData+MagicalRecord."` to `#import "M…
tonyarnold Apr 8, 2014
499300e
Add NSArray category to quickly retrieve and delete an array of manag…
tonyarnold Apr 8, 2014
72c112a
Use `+ [MagicalRecord defaultStoreName]` throughout the library
tonyarnold Apr 8, 2014
1645f18
Move logging options to the MagicalRecord+Options category
tonyarnold Apr 8, 2014
da03dc6
Add header comments for the `+[MagicalRecord logLevel]` accessor
tonyarnold Apr 8, 2014
d861127
Honour the return value from `-(BOOL)import<#AttributeName#>:` data i…
tonyarnold Apr 8, 2014
a3fe8e5
Remove unnecessary import
tonyarnold Apr 8, 2014
e367b29
Fix header imports for logging macros
tonyarnold Apr 8, 2014
b04e4e5
Remove unnecessary import
tonyarnold Apr 8, 2014
fee276b
Rename `kMagicalRecordImportUnixDate13String` to `kMagicalRecordImpor…
tonyarnold Apr 8, 2014
f08f09b
Fix the tests by updating the dateFormat to "UnixTime"
tonyarnold Jan 13, 2014
90e39e4
Initial pass at adding support for progressive migrations, based upon…
tonyarnold Apr 8, 2014
d4af937
Add method to do automatic saves when an observed context saves
tonyarnold Apr 8, 2014
390be03
Fix return type of aggregate methods — it's not guaranteed to be an N…
tonyarnold Apr 8, 2014
6922bf5
Expose minValueFor:/maxValueFor: methods that seem to have been dropp…
tonyarnold Apr 8, 2014
c96765e
Add `MR_findFirstOrCreateByAttribute:` methods to the MagicalFinders …
tonyarnold Apr 8, 2014
d4d1127
Update podspec for MR 3.0.0 (which isn't ready to go)
tonyarnold Apr 8, 2014
661ab25
Remove orphaned iCloudMagicalRecordStack implementation
tonyarnold Apr 8, 2014
4277a24
Replace `isEqualTo:` with `isEqual:`
tonyarnold Apr 8, 2014
45c1f17
Removing UIKit categories from the project for now
tonyarnold Apr 8, 2014
8d6e986
Fix broken test — it's not possible to retrieve permanent IDs for man…
tonyarnold Apr 8, 2014
d75d935
Don't ignore the error
tonyarnold Apr 8, 2014
d27cde2
Add build status to project home
tonyarnold Apr 8, 2014
2f5c3b3
Upgrade xctool before running tests
tonyarnold Apr 9, 2014
fea0f70
Print more information about the file remove error
tonyarnold Apr 9, 2014
10be38d
More detail in the error. I'm beginning to think this is TravisCI, no…
tonyarnold Apr 9, 2014
84466e6
Removing a persistent store should not return a status of NO if a fil…
tonyarnold Apr 9, 2014
c20b93b
Don't unnecessarily update xctool
tonyarnold Apr 9, 2014
5197782
Don't pollute the tests with logging
tonyarnold Apr 9, 2014
0fbea4a
Throw an exception when trying to resolve a temporary object in anoth…
tonyarnold Apr 9, 2014
b87a394
Fix return type of select and value/attribute finders
tonyarnold Apr 9, 2014
2d48087
Enable Mavericks image for testing on TravisCI
tonyarnold Apr 9, 2014
3843c6b
Latest Expecta
tonyarnold Apr 10, 2014
2823d9f
Add expected types to enumerations and other places where appropriate
tonyarnold Apr 10, 2014
eb5df4d
Update `MR_deleteInContext:` usage to `MR_deleteEntityInContext:`
tonyarnold Apr 10, 2014
ef7d11b
Git be silly
tonyarnold Apr 10, 2014
082c8e7
Git still be silly
tonyarnold Apr 10, 2014
5b3dbba
Add a contribution guide
tonyarnold Apr 10, 2014
e82c1c0
Remove an unnecessary log level check
tonyarnold Apr 10, 2014
1ef6cc7
Disable logging during tests
tonyarnold Apr 10, 2014
ffb7985
Remove requirement to defined MR_LOGGING_ENABLED before logging works.
tonyarnold Apr 10, 2014
0763bb4
Remove another instance of `MR_LOGGING_ENABLED` that I missed
tonyarnold Apr 10, 2014
14d82da
Format the save block for readability
tonyarnold Apr 10, 2014
aec6767
Replace `MR_entityName` with `MR_internalEntityName` to avoid infinit…
tonyarnold Apr 10, 2014
6b3f073
Fix Expecta submodule reference
casademora Apr 11, 2014
52df90e
Move the test scripts to a more appropriate location
tonyarnold Apr 11, 2014
a77ca78
Merge branch 'release/3.0' of github.com:magicalpanda/MagicalRecord i…
tonyarnold Apr 11, 2014
d6136fd
Latest Expecta
tonyarnold Apr 11, 2014
e0a2b8b
Fix `MR_internalEntityName` — NSManagedObject has a private method `e…
tonyarnold Apr 11, 2014
0ab2123
Replace checks for `entityName` on NSManagedObject subclasses with `n…
tonyarnold Apr 12, 2014
d649a90
Remove the shorthand entity name methods entirely
tonyarnold Apr 12, 2014
9965078
Make the `nameOfEntity` class method part of a protocol, not an inter…
tonyarnold Apr 12, 2014
92a28b9
Revert to `MR_entityName` for the time being
tonyarnold Apr 12, 2014
5b490f8
Add synchronous save methods that return a success state and optional…
tonyarnold Apr 12, 2014
7ae8db7
Don't dispatch save completion blocks to the main thread
tonyarnold Apr 12, 2014
b816e19
Save completion handlers no longer dispatch to the main thread by def…
tonyarnold Apr 12, 2014
3dad110
Entity attribute names must begin with a lowercase letter — update th…
xdream86 Apr 17, 2014
1b68f9b
Use the formal documentation warning parameter in Xcode's project set…
tonyarnold Apr 20, 2014
aa13fa0
Fix the logging so that it shows all log calls below the currently se…
tonyarnold Apr 20, 2014
6228da3
Add documentation for NSEntityDescription+MagicalDataImport.h
tonyarnold Apr 20, 2014
1023d2d
Add protocol for MOGenerator methods
tonyarnold Apr 20, 2014
3e531b4
Move NSArray+MagicalRecord to the Foundation directory
tonyarnold Apr 20, 2014
0520181
Who likes documentation? This guy!
tonyarnold Apr 20, 2014
356e09b
Rename the data import helper functions to follow Apple's function na…
tonyarnold Apr 20, 2014
72fda68
Rename category "MagicalRecord_DataImport" to "MagicalRecordDataImport"
tonyarnold Apr 20, 2014
38e658f
Latest Expecta
tonyarnold Apr 20, 2014
a003968
Fix the iOS color from string function
tonyarnold Apr 20, 2014
ac126e8
"-ObjC" is invalid unless we're building a dynamic library
tonyarnold Apr 20, 2014
fc865a3
88.4% documented
tonyarnold Apr 21, 2014
9088da3
Use modern Objective-C dictionary syntax
tonyarnold Apr 21, 2014
713b6a5
Document this!</worf>
tonyarnold Apr 21, 2014
058789b
Add a bit of documentation behind MR_awakeFromCreation
casademora Apr 23, 2014
2a5392d
Extract path creation to private standalone functions.
casademora Apr 27, 2014
fb7f31c
use MR_ prefix for copyToURL:error: method
casademora Apr 27, 2014
8824807
project updates
casademora Apr 27, 2014
d08a282
Merge branch 'release/3.0' of https://github.com/magicalpanda/Magical…
casademora Apr 27, 2014
e6fc89b
Make MOGeneratorProtocol header public for use with Mac Framework target
casademora Apr 27, 2014
a9ec615
Remove headerdoc comments that snuck into the implementation
tonyarnold Apr 25, 2014
afb4ac1
Fix NSFetchRequest example in documentation
tonyarnold Apr 27, 2014
2af80ac
Use functions to test for store locations
casademora Apr 27, 2014
426f8a0
Merge branch 'release/3.0' of https://github.com/magicalpanda/Magical…
casademora Apr 27, 2014
b4cf311
Make persistent store helper functions private
tonyarnold Apr 28, 2014
e891fd4
Be stricter in checking the logging level
tonyarnold Apr 28, 2014
768ef53
Fix logging configuration and macros
tonyarnold Apr 28, 2014
96e2c48
…and the rest of that commit *facepalm*
tonyarnold Apr 28, 2014
bcb47db
Rename MR_observeContext: method to MR_observeContexDidSave: for corr…
casademora May 7, 2014
800c6ce
Formatting!
casademora May 7, 2014
b7ff3e9
Update method signature in header to match implementation
casademora May 7, 2014
4515448
Latest Podspec changes, including a development version number
tonyarnold May 17, 2014
1c3ff4f
Reinstate the MR_LOGGING_ENABLED compile time checks for logging
tonyarnold May 17, 2014
4bef8e4
Update/Clean up Import Code
casademora May 17, 2014
3adc1d8
Rename logging enums :P
casademora May 17, 2014
6e1201e
Add option to autosave the default stack
casademora May 17, 2014
e4f898e
Cleanup code
casademora May 17, 2014
691ab4c
Use parent/child context merging for in memory store
casademora May 17, 2014
64c8449
Fixing broken tests, set merge policy on sqlite stores also
casademora May 17, 2014
2cd4211
I guess I've been writing for AppKit too much lately
casademora May 17, 2014
5d07029
Update logging documentation
tonyarnold May 18, 2014
fd959be
Formatting
tonyarnold May 18, 2014
602f11c
Update logging documentation
tonyarnold May 18, 2014
67eeeee
Move `MR_dateWithFormat:` category methods into the existing NSString…
tonyarnold May 19, 2014
ceac985
Silence unused variable warnings
tonyarnold May 19, 2014
41b7934
Resolve a type mismatch error by accepting NSPropertyDescription in p…
tonyarnold May 20, 2014
869cf7f
Silence a warning about an unused local variable which is being refer…
tonyarnold May 20, 2014
df1b15b
Add logging sub specs to the podspec.
tonyarnold May 20, 2014
00a784b
Use distinctAttribute to distinguish which attributes will be assumed…
casademora May 20, 2014
3299159
Merge branch 'release/3.0' of https://github.com/magicalpanda/Magical…
casademora May 20, 2014
26925fb
Change distinctAttribute contstant
casademora May 20, 2014
ed4f99d
Add inContext variant for `+MR_propertiesNamed:`
tonyarnold May 20, 2014
043db65
Update test data model to use `distinctAttribute` in place of `uniqui…
tonyarnold May 20, 2014
bffaf7c
Set a proper merge policy on the confinement contexts vended by the s…
casademora May 21, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "Tests/Support/Vendor/Specta"]
path = Tests/Support/Vendor/Specta
url = https://github.com/specta/specta.git
[submodule "Tests/Support/Vendor/Expecta"]
path = Tests/Support/Vendor/Expecta
url=https://github.com/tonyarnold/expecta.git
[submodule "Tests/Vendor/Expecta"]
path = Tests/Vendor/Expecta
url = https://github.com/specta/expecta.git
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: objective-c
script: Tests/Support/Scripts/objc-build-scripts/cibuild
osx_image: mavericks
75 changes: 75 additions & 0 deletions Changelog.md → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,80 @@
# Changelog

## Version 3.0

MagicalRecord 3.0 is a major release with new features and breaking changes.

### Stacks

MagicalRecord 3.0 introduces the concept of a 'Stack'. Applications can have a single stack, or many stacks. Library style applications like iPhoto or iTunes might only use a single stack, whereas a document-based application like TextEdit would usually use a stack for every open document.

It's easiest to think about a stack as all of the components necessary to interact with a single persistent store.

A stack includes the following basic objects:

```objc
@property (nonatomic, copy) NSString *stackName;

@property (nonatomic, strong) NSManagedObjectContext *context;
@property (nonatomic, strong) NSManagedObjectModel *model;
@property (nonatomic, strong) NSPersistentStoreCoordinator *coordinator;
@property (nonatomic, strong) NSPersistentStore *store;
```

To migrate a simple, existing MagicalRecord-based application to use stacks, it's as simple as replacing this:

```objc
[MagicalRecord setupAutoMigratingCoreDataStack];
```

with:

```objc
[MagicalRecordStack setDefaultStack:[AutoMigratingMagicalRecordStack stack]];
```

We recommend that you keep a reference to your stack somewhere other than the `defaultStack` property of the MagicalRecordStack class, so that if you need to add more than one stack it's an easier upgrade path. Also, Saul gets a bit crazy when people use singletons.

There are 9 stacks included by default:

#### SQLite Backed Stacks

All of the stacks below use SQLite-backed persistent stores (NSSQLiteStoreType).

1. **AutoMigratingMagicalRecordStack** will automatically perform all migrations provided by your project.

2. **AutoMigratingWithSourceAndTargetModelMagicalRecordStack** allows you define source and target managed object models to migrate directly between. It will not perform any additional migrations beyond those necessary to upgrade from the source model to the target.

3. **SQLiteMagicalRecordStack** provides a context that uses main queue concurrency.

4. **SQLiteWithSavingContextMagicalRecordStack** in addition to the main queue context, this stack provides a second, private background context that can be used to save changes without blocking the main thread.

3. **ClassicSQLiteMagicalRecordStack** provides a context that uses confinement concurrency when saving.

4. **ClassicWithBackgroundCoordinatorSQLiteMagicalRecordStack** in addition to the main queue context, provides a second, private background context that can be used to save changes without blocking the main thread.

4. **ManuallyMigratingMagicalRecordStack** does not automatically infer the mapping models to be used when performing migrations (`NSInferMappingModelAutomaticallyOption : NO` ).

#### iCloud Stack

**iCloudMagicalRecordStack** provides a SQLite-backed persistent store that configures a Ubiquity Container for iCloud.

#### In-Memory Stack

**InMemoryMagicalRecordStack** provides an in-memory persistent store. In-memory stacks are great for running import processes, or for use in your tests.


## Deprecations

* `MR_SHORTHAND` is deprecated in this release. You can continue using the shorthand methods, however clang will show a warning. If you absolutely must silence the deprecation warning, define `WE_PROMISE_TO_MIGRATE_TO_MAGICALRECORD_3_0` before you import any MagicalRecord header. Any method marked as deprecated in this release will be removed entirely in MagicalRecord 4.0, so please use these warnings to migrate your code to the non-shorthand methods.
* The **NSManagedObjectContext+MagicalThreading category has been removed entirely**. These methods are unnecessary alongside GCD, NSOperation and the `-performBlock:` and `-performBlockAndWait:` methods on NSManagedObjectContext. This includes the following methods:
- `+ (NSManagedObjectContext *) MR_contextForCurrentThread;`
- `+ (void) MR_clearNonMainThreadContextsCache;`
- `+ (void) MR_resetContextForCurrentThread;`
- `+ (void) MR_clearContextForCurrentThread;`



## Version 2.2
* Updated examples and fixed errors in README - [Tony Arnold](mailto:tony@thecocoabots.com)
* Changes block saves to use child context of rootSavingContext so that large saves do not channel through the default context and block the main thread - r-peck
Expand Down
25 changes: 25 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Thanks for contributing to this project!

To make the process as easy as possible, we've got a few guidelines that we'd appreciate you following:

## Filing Issues

Before you file an issue, please ensure that:

1. **It's a bug or a feature request** — if you're looking for help using MagicalRecord, please ask your question on [Stack Overflow](http://stackoverflow.com/). We monitor the [**MagicalRecord** tag](http://stackoverflow.com/questions/tagged/magicalrecord) so be sure to tag your question so that we see it
1. **Search for an existing issue** — there's a good chance you're not the only one experiencing the problem you've come to tell us about
2. **Include as much information as you can** — if we can't reproduce the problem you've filed, we can't fix it. Include crash logs, exception reports and code if you can.

## We Prefer Pull Requests

If you know exactly how to implement the feature being suggested or fix the bug being reported, please open a pull request instead of an issue. Pull requests are easier than patches or inline code blocks for discussing and merging the changes. Please ensure that you include tests in the Pull Request — we use XCTest with [Expecta](http://github.com/specta/expecta/).

If you can't make the change yourself, please open an issue after making sure that one isn't already logged.

## Contributing Code

Fork this repository, make some great changes (preferably in a branch named for the topic of the changes you're making) and send a pull request!

All code contributions should match our [coding conventions](/magicalpanda/MagicalRecord/wiki/Coding-Conventions).

Thanks for reading the guidelines!
151 changes: 84 additions & 67 deletions Docs/Fetching.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,132 +2,149 @@

#### Basic Finding

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:
Most methods in MagicalRecord return an `NSArray` of results.

//In order for this to work you need to add "#define MR_SHORTHAND" to your PCH file
NSArray *people = [Person findAll];
Say you have an Entity called "Person", related to a Department (as seen in various Apple Core Data documentation). To get all of the Person entities from your Persistent Store, use the following method:

// Otherwise you can use the longer, namespaced version
NSArray *people = [Person MR_findAll];
```objective-c
NSArray *people = [Person MR_findAll];
```

Or, to have the results sorted by a property:
Or, to return the results sorted by a property:

NSArray *peopleSorted = [Person MR_findAllSortedBy:@"LastName" ascending:YES];
```objective-c
NSArray *peopleSorted = [Person MR_findAllSortedBy:@"LastName" ascending:YES];
```

Or, to have the results sorted by multiple properties:
Or, to return the results sorted by multiple properties:

NSArray *peopleSorted = [Person MR_findAllSortedBy:@"LastName,FirstName" ascending:YES];
```objective-c
NSArray *peopleSorted = [Person MR_findAllSortedBy:@"LastName,FirstName" ascending:YES];
```

Or, to have the results sorted by multiple properties with difference attributes - will default to whatever you set it to:
Or, to return the results sorted by multiple properties with different attributes (these will default to whatever you set them to):

NSArray *peopleSorted = [Person MR_findAllSortedBy:@"LastName:NO,FirstName" ascending:YES];
```objective-c
NSArray *peopleSorted = [Person MR_findAllSortedBy:@"LastName:NO,FirstName" ascending:YES];

NSArray *peopleSorted = [Person MR_findAllSortedBy:@"LastName,FirstName:YES" ascending:NO];
// OR

If you have a unique way of retrieving a single object from your data store, you can get that object directly:
NSArray *peopleSorted = [Person MR_findAllSortedBy:@"LastName,FirstName:YES" ascending:NO];
```

Person *person = [Person MR_findFirstByAttribute:@"FirstName" withValue:@"Forrest"];
If you have a unique way of retrieving a single object from your data store (such as via an identifier), you can use the following method:

```objective-c
Person *person = [Person MR_findFirstByAttribute:@"FirstName" withValue:@"Forrest"];
```

#### Advanced Finding

If you want to be more specific with your search, you can send in a predicate:

NSArray *departments = [NSArray arrayWithObjects:dept1, dept2, ..., nil];
NSPredicate *peopleFilter = [NSPredicate predicateWithFormat:@"Department IN %@", departments];

NSArray *people = [Person MR_findAllWithPredicate:peopleFilter];
```objective-c
NSPredicate *peopleFilter = [NSPredicate predicateWithFormat:@"Department IN %@", @[dept1, dept2]];
NSArray *people = [Person MR_findAllWithPredicate:peopleFilter];
```

#### Returning an NSFetchRequest

NSPredicate *peopleFilter = [NSPredicate predicateWithFormat:@"Department IN %@", departments];

NSArray *people = [Person MR_findAllWithPredicate:peopleFilter];
```objective-c
NSPredicate *peopleFilter = [NSPredicate predicateWithFormat:@"Department IN %@", departments];
NSFetchRequest *people = [Person MR_requestAllWithPredicate:peopleFilter];
```

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.

#### Customizing the Request

NSPredicate *peopleFilter = [NSPredicate predicateWithFormat:@"Department IN %@", departments];
```objective-c
NSPredicate *peopleFilter = [NSPredicate predicateWithFormat:@"Department IN %@", departments];

NSFetchRequest *peopleRequest = [Person MR_requestAllWithPredicate:peopleFilter];
[peopleRequest setReturnsDistinctResults:NO];
[peopleRequest setReturnPropertiesNamed:[NSArray arrayWithObjects:@"FirstName", @"LastName", nil]];
...
NSFetchRequest *peopleRequest = [Person MR_requestAllWithPredicate:peopleFilter];
[peopleRequest setReturnsDistinctResults:NO];
[peopleRequest setReturnPropertiesNamed:@[@"FirstName", @"LastName"]];

NSArray *people = [Person MR_executeFetchRequest:peopleRequest];
NSArray *people = [Person MR_executeFetchRequest:peopleRequest];
```

#### Find the number of entities

You can also perform a count of entities in your Store, that will be performed on the Store
You can also perform a count of all entities of a specific type in your Persistent Store:

NSNumber *count = [Person MR_numberOfEntities];
```objective-c
NSNumber *count = [Person MR_numberOfEntities];
```

Or, if you're looking for a count of entities based on a predicate or some filter:

NSNumber *count = [Person MR_numberOfEntitiesWithPredicate:...];
There are also counterpart methods which return NSUInteger rather than NSNumbers:
```objective-c
NSNumber *count = [Person MR_numberOfEntitiesWithPredicate:...];
```

* countOfEntities
* countOfEntitiesWithContext:(NSManagedObjectContext *)
* countOfEntitiesWithPredicate:(NSPredicate *)
* countOfEntitiesWithPredicate:(NSPredicate *) inContext:(NSManagedObjectContext *)
There are also complementary methods which return `NSUInteger` rather than `NSNumber` instances:

* `MR_countOfEntities`
* `MR_countOfEntitiesWithContext:(NSManagedObjectContext *)context`
* `MR_countOfEntitiesWithPredicate:(NSPredicate *)predicate`
* `MR_countOfEntitiesWithPredicate:(NSPredicate *)predicatecontext inContext:(NSManagedObjectContext *)`

#### Aggregate Operations

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"diaryEntry.date == %@", today];
int totalFat = [[CTFoodDiaryEntry MR_aggregateOperation:@"sum:" onAttribute:@"fatColories" withPredicate:predicate] intValue];
int fattest = [[CTFoodDiaryEntry MR_aggregateOperation:@"max:" onAttribute:@"fatColories" withPredicate:predicate] intValue];

```objective-c
NSInteger totalFat = [[CTFoodDiaryEntry MR_aggregateOperation:@"sum:" onAttribute:@"fatCalories" withPredicate:predicate] integerValue];
NSInteger fattest = [[CTFoodDiaryEntry MR_aggregateOperation:@"max:" onAttribute:@"fatCalories" withPredicate:predicate] integerValue];
NSArray *caloriesByMonth = [CTFoodDiaryEntry MR_aggregateOperation:@"sum:" onAttribute:@"fatCalories" withPredicate:predicate groupBy:@"month"];
```

#### Finding from a different context

All find, fetch, and request methods have an inContext: method parameter

NSManagedObjectContext *someOtherContext = ...;

NSArray *peopleFromAnotherContext = [Person MR_findAllInContext:someOtherContext];
```objective-c
NSArray *peopleFromAnotherContext = [Person MR_findAllInContext:someOtherContext];

...

Person *personFromContext = [Person MR_findFirstByAttribute:@"lastName" withValue:@"Gump" inContext:someOtherContext];

...

NSUInteger count = [Person MR_numberOfEntitiesWithContext:someOtherContext];
Person *personFromContext = [Person MR_findFirstByAttribute:@"lastName" withValue:@"Gump" inContext:someOtherContext];

NSUInteger count = [Person MR_numberOfEntitiesWithContext:someOtherContext];
```

## Creating new Entities

When you need to create a new instance of an Entity, use:

Person *myNewPersonInstance = [Person MR_createEntity];
```objective-c
Person *myPerson = [Person MR_createEntity];
```

or, to specify a context:

NSManagedObjectContext *otherContext = ...;

Person *myPerson = [Person MR_createInContext:otherContext];
or, to specify which context the entity is inserted into:

```objective-c
Person *myPerson = [Person MR_createEntityInContext:otherContext];
```

## Deleting Entities

To delete a single entity:

Person *p = ...;
[p MR_deleteEntity];

or, to specify a context:
```objective-c
[myPerson MR_deleteEntity];
```

NSManagedObjectContext *otherContext = ...;
Person *deleteMe = ...;
or, to delete the entity from a specific context:

[deleteMe MR_deleteInContext:otherContext];
```objective-c
[myPerson MR_deleteEntityInContext:otherContext];
```

There is no delete *All Entities* or *truncate* operation in core data, so one is provided for you with Active Record for Core Data:

[Person MR_truncateAll];
```objective-c
[Person MR_truncateAll];
```

or, with a specific context:
or, to truncate all entities in a specific context:

NSManagedObjectContext *otherContext = ...;
[Person MR_truncateAllInContext:otherContext];
```objective-c
[Person MR_truncateAllInContext:otherContext];
```
2 changes: 1 addition & 1 deletion Docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## Setting up the Core Data Stack

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.
To get started, first, import the header file *MagicalRecord.h* in your project's pch file. This will allow a global include of all the required headers.
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 **MagicalRecord** class:

+ (void) setupCoreDataStack;
Expand Down
6 changes: 3 additions & 3 deletions Docs/Installation.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Installation

1. In your XCode Project, drag the *MagicalRecord* folder (under the main folder) into your project.
2. Add *CoreData+MagicalRecord.h* file to your PCH file or your AppDelegate file.
3. Optionally preceed the *CoreData+MagicalRecord.h* import with `#define MR_SHORTHAND` to your PCH file if you want to use MagicalRecord methods without the *MR_prefix* like `findAll` instead of `MR_findAll`
1. In your Xcode Project, drag the *MagicalRecord* folder (under the main folder) into your project.
2. Add *MagicalRecord.h* file to your PCH file or your AppDelegate file.
3. Optionally precede the *MagicalRecord.h* import with `#define MR_SHORTHAND` to your PCH file if you want to use MagicalRecord methods without the *MR_prefix* like `findAll` instead of `MR_findAll`
4. Start writing code!

# Requirements
Expand Down
Loading