Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Completely revise, test and document save behaviour for MagicalRecord 2.1 #341

Closed
wants to merge 28 commits into from

3 participants

Tony Arnold bcyng iOSDevil
Tony Arnold
Owner

This is a big change, but it's covered in unit tests and has been documented. I'll copy and paste the changes from the README:

Changes to saving

The APIs for saving have been revised to behave more consistently overall, and also to follow naming patterns present in Core Data. Extensive work has gone into adding automated tests that ensure the save methods (both new and deprecated) continue to work as expected through future updates.

MR_save has been temporarily restored to it's original state of running synchronously on the current thread, and saving to the persistent store. However, the MR_save method is marked as deprecated and will be removed in the next major release of MagicalRecord (version 3.0). You should use MR_saveToPersistentStoreAndWait if you want the same behaviour in future versions of the library.

New Methods

The following methods have been added:

NSManagedObjectContext+MagicalSaves

  • - (void) MR_saveOnlySelfWithCompletion:(MRSaveCompletionHandler)completion;
  • - (void) MR_saveToPersistentStoreWithCompletion:(MRSaveCompletionHandler)completion;
  • - (void) MR_saveOnlySelfAndWait;
  • - (void) MR_saveToPersistentStoreAndWait;
  • - (void) MR_saveWithOptions:(MRSaveContextOptions)mask completion:(MRSaveCompletionHandler)completion;

MagicalRecord+Actions

  • + (void) saveWithBlock:(void(^)(NSManagedObjectContext *localContext))block;
  • + (void) saveWithBlock:(void(^)(NSManagedObjectContext *localContext))block completion:(MRSaveCompletionHandler)completion;
  • + (void) saveWithBlockAndWait:(void(^)(NSManagedObjectContext *localContext))block;
  • + (void) saveUsingCurrentThreadContextWithBlock:(void (^)(NSManagedObjectContext *localContext))block completion:(MRSaveCompletionHandler)completion;
  • + (void) saveUsingCurrentThreadContextWithBlockAndWait:(void (^)(NSManagedObjectContext *localContext))block;

Deprecations

The following methods have been deprecated in favour of newer alternatives, and will be removed in MagicalRecord 3.0:

NSManagedObjectContext+MagicalSaves

  • - (void) MR_save;
  • - (void) MR_saveWithErrorCallback:(void(^)(NSError *error))errorCallback;
  • - (void) MR_saveInBackgroundCompletion:(void (^)(void))completion;
  • - (void) MR_saveInBackgroundErrorHandler:(void (^)(NSError *error))errorCallback;
  • - (void) MR_saveInBackgroundErrorHandler:(void (^)(NSError *error))errorCallback completion:(void (^)(void))completion;
  • - (void) MR_saveNestedContexts;
  • - (void) MR_saveNestedContextsErrorHandler:(void (^)(NSError *error))errorCallback;
  • - (void) MR_saveNestedContextsErrorHandler:(void (^)(NSError *error))errorCallback completion:(void (^)(void))completion;

MagicalRecord+Actions

  • + (void) saveWithBlock:(void(^)(NSManagedObjectContext *localContext))block;
  • + (void) saveInBackgroundWithBlock:(void(^)(NSManagedObjectContext *localContext))block;
  • + (void) saveInBackgroundWithBlock:(void(^)(NSManagedObjectContext *localContext))block completion:(void(^)(void))completion;
  • + (void) saveInBackgroundUsingCurrentContextWithBlock:(void (^)(NSManagedObjectContext *localContext))block completion:(void (^)(void))completion errorHandler:(void (^)(NSError *error))errorHandler;
tonyarnold added some commits
Tony Arnold tonyarnold New save behaviour.
Older methods have been deprecated formally, and will be removed in the
next major release.
`MR_save` now behaves as it did pre-2.0.8.
c505f54
Tony Arnold tonyarnold Use the new save methods 5616f1a
Tony Arnold tonyarnold Update existing save tests to reflect save changes. Also begin adding…
… tests for deprecated methods to ensure consistent behaviour in unmodified code.
a525594
Tony Arnold tonyarnold Update other tests to use the new save methods 4ac3b26
Tony Arnold tonyarnold Fix compilation problems under latest Xcode. c90747b
Tony Arnold tonyarnold Rename saveParentContexts methods to saveToPersistentStore f00538c
Tony Arnold tonyarnold The completion block should still run when there are no changes, with…
… a success status of NO
7499d7f
Tony Arnold tonyarnold Ensure that the block variables have properly named parameters c7321b6
Tony Arnold tonyarnold The root save method should always be performed synchronously (to the…
… thread it is called from)
fb24dd1
Tony Arnold tonyarnold Update tests to use new new save methods 47f8cec
Tony Arnold tonyarnold Moar test method cleanups e85fcaf
Tony Arnold tonyarnold Changes recommended by Xcode 3161ce8
Tony Arnold tonyarnold Revised save tests d372914
Tony Arnold tonyarnold Remove xcuserdata 47a7080
Tony Arnold tonyarnold Updated gitignore ec9a919
Tony Arnold tonyarnold Add Kiwi for saner asynchronous testing bd88caa
Tony Arnold tonyarnold Flesh out tests for MagicalRecord+Actions and the NSManagedObjectCont…
…ext+MagicalSaves category
957b5c8
Tony Arnold tonyarnold Log when saving has finished 27c9d78
Tony Arnold tonyarnold Remove GHUnit save tests in favour of Kiwi equivalents f51fd25
Tony Arnold tonyarnold The deprecated saveWithBlock: method should do it's work on the curre…
…nt thread
4c620e5
Tony Arnold tonyarnold All deprecated methods in MagicalRecord+Actions are now tested for ba…
…sic function
72f6080
Tony Arnold tonyarnold Clean up warnings about deprecated methods where it's legitimate 0c72ba8
Tony Arnold tonyarnold All deprecated and non-deprecated methods have tests to ensure their …
…function
c123205
Tony Arnold tonyarnold Xcoaaaaad! b9d6969
Tony Arnold tonyarnold Update README with details of the changes in this branch 7ce2e15
bcyng

i think the shorthand methods for these methods (at least saveToPersistentStoreAndWait) are missing?
(this is great stuff btw).

iOSDevil
Tony Arnold
Owner

Thanks @bcyng — I'll add them later today.

@iOSDevil give me a day or two to merge this properly, and then it'll be available from the develop branch.

Tony Arnold
Owner

Closed in favour of the more concise #343

Tony Arnold tonyarnold closed this
Tony Arnold tonyarnold deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 12, 2012
  1. Tony Arnold

    New save behaviour.

    tonyarnold authored
    Older methods have been deprecated formally, and will be removed in the
    next major release.
    `MR_save` now behaves as it did pre-2.0.8.
  2. Tony Arnold

    Use the new save methods

    tonyarnold authored
  3. Tony Arnold

    Update existing save tests to reflect save changes. Also begin adding…

    tonyarnold authored
    … tests for deprecated methods to ensure consistent behaviour in unmodified code.
  4. Tony Arnold
  5. Tony Arnold
Commits on Dec 13, 2012
  1. Tony Arnold
  2. Tony Arnold
  3. Tony Arnold
  4. Tony Arnold
  5. Tony Arnold
  6. Tony Arnold

    Moar test method cleanups

    tonyarnold authored
  7. Tony Arnold
  8. Tony Arnold

    Revised save tests

    tonyarnold authored
  9. Tony Arnold

    Remove xcuserdata

    tonyarnold authored
  10. Tony Arnold

    Updated gitignore

    tonyarnold authored
Commits on Dec 14, 2012
  1. Tony Arnold
  2. Tony Arnold
  3. Tony Arnold
  4. Tony Arnold
  5. Tony Arnold
  6. Tony Arnold
  7. Tony Arnold
  8. Tony Arnold
  9. Tony Arnold

    Xcoaaaaad!

    tonyarnold authored
  10. Tony Arnold
  11. Tony Arnold
  12. Tony Arnold
Commits on Dec 15, 2012
  1. Tony Arnold

    Update shorthand methods

    tonyarnold authored
Something went wrong with that request. Please try again.