Skip to content

Commit

Permalink
Merge pull request #76 from chillpop/feature/parent-child
Browse files Browse the repository at this point in the history
Parent/Child Contexts
  • Loading branch information
chillpop committed Feb 12, 2016
2 parents 509f49a + 9d58205 commit 57cddfc
Show file tree
Hide file tree
Showing 25 changed files with 611 additions and 399 deletions.
28 changes: 14 additions & 14 deletions Paging Data Source Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
PODS:
- ILGDynamicObjC/ILGClasses (0.1.1)
- Vokoder (2.3.1):
- Vokoder/Core (= 2.3.1)
- Vokoder/DataSources (= 2.3.1)
- Vokoder/MapperMacros (= 2.3.1)
- Vokoder/Core (2.3.1):
- Vokoder (3.0.0):
- Vokoder/Core (= 3.0.0)
- Vokoder/DataSources (= 3.0.0)
- Vokoder/MapperMacros (= 3.0.0)
- Vokoder/Core (3.0.0):
- ILGDynamicObjC/ILGClasses (~> 0.1.1)
- VOKUtilities/VOKKeyPathHelper (~> 0.8.0)
- Vokoder/DataSources (2.3.1):
- Vokoder/DataSources (3.0.0):
- Vokoder/Core
- Vokoder/DataSources/Collection (= 2.3.1)
- Vokoder/DataSources/FetchedResults (= 2.3.1)
- Vokoder/DataSources/PagingFetchedResults (= 2.3.1)
- Vokoder/DataSources/Collection (2.3.1):
- Vokoder/DataSources/Collection (= 3.0.0)
- Vokoder/DataSources/FetchedResults (= 3.0.0)
- Vokoder/DataSources/PagingFetchedResults (= 3.0.0)
- Vokoder/DataSources/Collection (3.0.0):
- Vokoder/Core
- Vokoder/DataSources/FetchedResults
- Vokoder/DataSources/FetchedResults (2.3.1):
- Vokoder/DataSources/FetchedResults (3.0.0):
- Vokoder/Core
- Vokoder/DataSources/PagingFetchedResults (2.3.1):
- Vokoder/DataSources/PagingFetchedResults (3.0.0):
- Vokoder/Core
- Vokoder/DataSources/FetchedResults
- Vokoder/MapperMacros (2.3.1):
- Vokoder/MapperMacros (3.0.0):
- Vokoder/Core
- VOKUtilities/VOKKeyPathHelper (0.8.0)
- xUnique (4.1.2)
Expand All @@ -43,7 +43,7 @@ CHECKOUT OPTIONS:

SPEC CHECKSUMS:
ILGDynamicObjC: 63443567f8ce851067ea3070d3b8c7f93d37207c
Vokoder: fc60909b0d3410d3abdc1af7ba01f7e9b6f1198e
Vokoder: 2f0a9f0a1e76768edf30f1ddbfb07f2ba6b9a84c
VOKUtilities: 7d579a7fa5304c2eec17c49d293b2554d6059eaa
xUnique: 7f74d3f52c7769f648aa7be8fe614fc27dba2405

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions Paging Data Source Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 0 additions & 32 deletions Pod/Classes/MapperMacros/VOKManagedObjectMapperMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,4 @@
[VOKManagedObjectMap mapWithForeignKeyPath:inputKeyPath coreDataKey:VOKKeyForSelf(coreDataSelectorSymbol)]
#endif


////////////////////////// DEPRECATED MACROS //////////////////////////

/**
* Generate a string from a selector symbol.
*
* @param selectorSymbol The selector symbol.
*
* @return An NSString
*/
#ifndef VOK_CDSELECTOR
# ifdef DEBUG
# define VOK_CDSELECTOR(selectorSymbol) _Pragma ("GCC warning \"'VOK_CDSELECTOR' macro is deprecated and will be removed in version 3.0. Use the appropriate macro from VOKUtilities/VOKKeyPathHelper instead.\"") NSStringFromSelector(@selector(selectorSymbol))
# else
# define VOK_CDSELECTOR(selectorSymbol) _Pragma ("GCC warning \"'VOK_CDSELECTOR' macro is deprecated and will be removed in version 3.0. Use the appropriate macro from VOKUtilities/VOKKeyPathHelper instead.\"") @#selectorSymbol //in release builds @#selectorSymbol becomes @"{selectorSymbol}"
# endif
#endif

/**
* Creates a map with the default date mapper.
*
* @param inputKeyPath The foreign key to match with the local key.
* @param coreDataSelectorSymbol The local selector symbol.
*
* @return A VOKManagedObjectMap
*/
#ifndef VOK_MAP_FOREIGN_TO_LOCAL
# define VOK_MAP_FOREIGN_TO_LOCAL(inputKeyPath, coreDataSelectorSymbol) \
_Pragma ("GCC warning \"'VOK_MAP_FOREIGN_TO_LOCAL' macro is deprecated and will be removed in version 3.0. Use VOKMapForeignToLocalClassProperty or VOKMapForeignToLocalForSelf instead.\"") \
[VOKManagedObjectMap mapWithForeignKeyPath:inputKeyPath coreDataKey:VOK_CDSELECTOR(coreDataSelectorSymbol)]
#endif

#endif /* VOKManagedObjectMapperMacros_h */
33 changes: 22 additions & 11 deletions Pod/Classes/VOKCoreDataManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ typedef void(^VOKObjectIDsReturnBlock)(VOKArrayOfManagedObjectIDs *managedObject
*/
+ (VOKCoreDataManager *)sharedInstance;

///The primary managed object context. Only for use on the main queue.
/**The primary managed object context. Only for use on the main queue.
All access to managed objects should happen through this context or a temporary context.
*/
@property (nonatomic, strong, readonly) NSManagedObjectContext *managedObjectContext;

/// The managed object model, based on the resource and database.
Expand Down Expand Up @@ -243,39 +245,41 @@ typedef void(^VOKObjectIDsReturnBlock)(VOKArrayOfManagedObjectIDs *managedObject
context:(nullable NSManagedObjectContext *)contextOrNil;

/**
Saves the main context asynchronously on the main queue. If already on the main queue it will block and save synchronously.
Saves the main context asynchronously.
*/
- (void)saveMainContext;

/**
Saves the main context synchronously on the main queue. If already on the main queue it performs the same as saveMainContext.
Saves the main context synchronously. This method will not return until the main context is saved.
*/
- (void)saveMainContextAndWait;

/**
Provides a managed object context for scratch work or background processing using the same persistent store coordinator as the main context. As with all managed object contexts, it is not thread-safe.
Create the context and do work on the same queue. You are responsible for retaining temporary contexts yourself.
Provides a managed object context for scratch work or background processing as a child of the main context. As with all managed object contexts, it is thread-safe as long as you use it with its 'performBlock...' methods.
Create the context and do work using performBlock: or performBlockAndWait:. You are responsible for retaining temporary contexts yourself.
Here is an example background import:
@code
NSManagedObjectContext *backgroundContext = [[VOKCoreDataManager sharedInstance] temporaryContext];
[self loadDataWithContext:backgroundContext]; //do some data loading
[backgroundContext performBlockAndWait:^{
[self loadDataWithContext:backgroundContext]; //do some data loading
}];
[[VOKCoreDataManager sharedInstance] saveAndMergeWithMainContext:backgroundContext];
@endcode
@return A managed object context with the same persistent store coordinator as the main context, but otherwise no relationship.
@return A managed object context with the main context as its parent.
*/
- (NSManagedObjectContext *)temporaryContext;

/**
This provides a way for an application with heavy amounts of Core Data threading and writing to maintain object graph integrety by assuring that only one context is being written to at once.
@param writeBlock Do not save or merge this context, it will be done for you. Do not use GCD or thread jumping inside this block.
@param writeBlock Do not save or merge this context, it will be done for you.
Handle all fetches, creates and writes using the tempContext variable passed to this block.
@prarm completion Fired on the main queue once the changes have been merged.
*/
+ (void)writeToTemporaryContext:(VOKWriteBlock)writeBlock
completion:(nullable void (^)(void))completion;

/**
Deserializes an NSArray full of NSDictionaries in the background and creates/updates instances in the given context.
Deserializes an NSArray full of NSDictionaries in the background and creates/updates instances in a temporary context.
@param inputArray An NSArray of NSDictionaries with data to be deserialized, imported, and merged into the main managed object context.
@param objectClass Specifies the class to instantiate or fetch when importing data.
@param completion Fired on the main queue once the changes have been merged. It brings an NSArray of permanent NSManagedObjectIDs matching the objects deserialized from the import array.
Expand All @@ -285,12 +289,19 @@ typedef void(^VOKObjectIDsReturnBlock)(VOKArrayOfManagedObjectIDs *managedObject
completion:(nullable VOKObjectIDsReturnBlock)completion;

/**
Saves any temporary managed object context and merges those changes with the main managed object context in a thread-safe way.
Saves any temporary managed object context and merges those changes with the main managed object context asynchronously.
This method is safe to call from any queue.
@param context The termporary context to save. Do not use this method to save the main context.
@param context The temporary context to save.
*/
- (void)saveAndMergeWithMainContext:(NSManagedObjectContext *)context;

/**
Saves any temporary managed object context and merges those changes with the main managed object context synchronously.
This method is safe to call from any queue. This method will not return until the main context is saved.
@param context The temporary context to save.
*/
- (void)saveAndMergeWithMainContextAndWait:(NSManagedObjectContext *)context;

/**
Deletes the persistent stores and resets the main context and model to nil
*/
Expand Down
Loading

0 comments on commit 57cddfc

Please sign in to comment.