From 3558ce0b219efb6d004cea672eff37f5d2ae1c9e Mon Sep 17 00:00:00 2001 From: masakih Date: Sun, 29 Nov 2015 00:54:13 +0900 Subject: [PATCH] =?utf8?q?=E3=82=AF=E3=83=A9=E3=83=83=E3=82=B7=E3=83=A5?= =?utf8?q?=E3=81=97=E3=81=9F=E6=99=82=E3=81=AB=E3=83=86=E3=82=99=E3=83=BC?= =?utf8?q?=E3=82=BF=E3=81=8B=E3=82=99=E4=BF=9D=E5=AD=98=E3=81=95=E3=82=8C?= =?utf8?q?=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C=E3=82=92=E8=A7=A3=E6=B6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit #35500 close --- KCD/HMCoreDataManager.m | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/KCD/HMCoreDataManager.m b/KCD/HMCoreDataManager.m index 1d108449..4ae3502b 100644 --- a/KCD/HMCoreDataManager.m +++ b/KCD/HMCoreDataManager.m @@ -55,11 +55,6 @@ typedef NS_ENUM(NSUInteger, HMCoreDataManagerType) { - (void)dealloc { [self saveAction:nil]; - - NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - [nc removeObserver:[[self class] defaultManager] - name:NSManagedObjectContextDidSaveNotification - object:self.managedObjectContext]; } - (NSArray *)objectsWithEntityName:(NSString *)entityName sortDescriptors:(NSArray *)sortDescriptors predicate:(NSPredicate *)predicate error:(NSError **)error @@ -235,6 +230,20 @@ typedef NS_ENUM(NSUInteger, HMCoreDataManagerType) { }); } } + + NSManagedObjectContext *mainContext = self.managedObjectContext.parentContext; + [mainContext performBlock:^{ // do nothing if mainContext is nil. + NSError *error = nil; + if(![mainContext save:&error]) { + if([NSThread isMainThread]) { + [[NSApplication sharedApplication] presentError:error]; + } else { + dispatch_sync(dispatch_get_main_queue(), ^{ + [[NSApplication sharedApplication] presentError:error]; + }); + } + } + }]; } - (void)applicationWillTerminate:(NSNotification *)notification -- 2.11.0