Permalink
Browse files

Remove the worker thread method from DCTCoreDataStack

  • Loading branch information...
danielctull committed Aug 2, 2012
1 parent 93ce9b5 commit f7fd56e6ed112f9033ccabbbe853974af4898936
@@ -109,14 +109,6 @@ extern NSString *const DCTCoreDataStackExcludeFromBackupStoreOption;
[NSManagedObjectContext dct_saveWithCompletionHandler:](../Categories/NSManagedObjectContext%28DCTCoreDataStack%29.html#//api/name/dct_saveWithCompletionHandler:) is used. */
@property (nonatomic, readonly) NSManagedObjectContext *managedObjectContext;
-/** Generates a new private context to do background work on.
-
- This is a sibling to the managedObjectContext and saves to this context will merge across
- to the managedObjectContext. Changes to the managedObjectContext will not merge across
- to the context given from this method, and should be handled by the user if desired.
- */
-- (NSManagedObjectContext *)newWorkerManagedObjectContext;
-
/// @name Configuration State
/** The URL of the persistent store file. */
@@ -60,12 +60,9 @@ @implementation DCTCoreDataStack {
#pragma mark - NSObject
- (void)dealloc {
- NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
- [defaultCenter removeObserver:self
- name:NSManagedObjectContextDidSaveNotification
- object:_rootContext];
#ifdef TARGET_OS_IPHONE
+ NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
UIApplication *app = [UIApplication sharedApplication];
[defaultCenter removeObserver:self
name:UIApplicationDidEnterBackgroundNotification
@@ -106,10 +103,6 @@ - (id)initWithStoreURL:(NSURL *)storeURL
_rootContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
[_rootContext setPersistentStoreCoordinator:self.persistentStoreCoordinator];
_rootContext.dct_name = @"DCTCoreDataStack.internal_rootContext";
- [defaultCenter addObserver:self
- selector:@selector(_rootContextDidSaveNotification:)
- name:NSManagedObjectContextDidSaveNotification
- object:_rootContext];
#ifdef TARGET_OS_IPHONE
@@ -140,16 +133,13 @@ - (id)initWithStoreFilename:(NSString *)filename {
#pragma mark - Getters
-- (NSManagedObjectContext *)newWorkerManagedObjectContext {
- return [self _newManagedObjectContextWithName:@"DCTCoreDataStack.workerContext"
- concurrencyType:NSPrivateQueueConcurrencyType];
-}
-
- (NSManagedObjectContext *)managedObjectContext {
- if (_managedObjectContext == nil)
- _managedObjectContext = [self _newManagedObjectContextWithName:@"DCTCoreDataStack.mainContext"
- concurrencyType:NSMainQueueConcurrencyType];
+ if (_managedObjectContext == nil) {
+ _managedObjectContext = [[_DCTCDSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
+ [_managedObjectContext setParentContext:_rootContext];
+ _managedObjectContext.dct_name = @"DCTCoreDataStack.mainContext";
+ }
return _managedObjectContext;
}
@@ -172,15 +162,6 @@ - (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
return _persistentStoreCoordinator;
}
-- (NSManagedObjectContext *)_newManagedObjectContextWithName:(NSString *)name
- concurrencyType:(NSManagedObjectContextConcurrencyType)concurrencyType {
-
- NSManagedObjectContext *managedObjectContext = [[_DCTCDSManagedObjectContext alloc] initWithConcurrencyType:concurrencyType];
- [managedObjectContext setParentContext:_rootContext];
- managedObjectContext.dct_name = name;
- return managedObjectContext;
-}
-
- (void)_loadManagedObjectModel {
if (self.modelURL)
@@ -252,12 +233,6 @@ - (void)_setupExcludeFromBackupFlag {
}
}
-- (void)_rootContextDidSaveNotification:(NSNotification *)notification {
- [self.managedObjectContext performBlock:^{
- [self.managedObjectContext mergeChangesFromContextDidSaveNotification:notification];
- }];
-}
-
+ (NSURL *)_applicationDocumentsDirectory {
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}
@@ -10,6 +10,14 @@
@interface NSManagedObjectContext (DCTSiblingContext)
+/** Generates a new private context to do background work on.
+
+ This is a sibling to the managedObjectContext and saves to this context will merge across
+ to the managedObjectContext. Changes to the managedObjectContext will not merge across
+ to the context given from this method, and should be handled by the user if desired.
+
+ @param concurrencyType The concurrency type to use, which is almost defintely going to be NSPrivateQueueConcurrencyType.
+ */
- (NSManagedObjectContext *)dct_newSiblingContextWithConcurrencyType:(NSManagedObjectContextConcurrencyType)concurrencyType;
@end

0 comments on commit f7fd56e

Please sign in to comment.