core data - Saving a UIManagedDocument - speed improvements -


i have following code used on view controller whenever property 'document' (of type uimanageddocument) set.

i'm not sure if other people do, find notion of concurrency in core data confusing, documents have go @ explaining it's still hard grips with. reason, wondering if people had ideas of how speed code use saving newly set uidocument if not exist. code work, if others use it.

my main goal try , make time takes document save , load faster. takes 20 seconds this, way long!

[[uiapplication sharedapplication] setnetworkactivityindicatorvisible:yes];  if (![[nsfilemanager defaultmanager] fileexistsatpath:self.documentdatabase.fileurl.path]) {     [self.documentdatabase savetourl:self.documentdatabase.fileurl                     forsaveoperation:uidocumentsaveforcreating                    completionhandler:^(bool success) {                        [[uiapplication sharedapplication] setnetworkactivityindicatorvisible:no];                         if (success) {                            nslog(@"saved %@", self.documentdatabase.localizedname);                             dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{                                [self.documentdatabase.managedobjectcontext performblockandwait:^{                                    dispatch_async(dispatch_get_main_queue(), ^{                                        [book newbookwithtitle:self.documentdatabase.fileurl.lastpathcomponent.stringbydeletingpathextension inmanagedobjectcontext:self.documentdatabase.managedobjectcontext];                                         [self savedocumentwithcompletionhandler:^(bool success) {                                            if (success) {                                                [self setisdocumenthidden:no];                                            }                                        }];                                         nslog(@"added default note %@", self.documentdatabase.fileurl.lastpathcomponent);                                    });                                }];                            });                        } else {                            nslog(@"error saving %@", self.documentdatabase.fileurl.lastpathcomponent);                        }                    }]; } else {     [self opendocumentwithcompletionhandler:nil]; } 

20 seconds sounds bit extreme, unless you're dealing vast database. have tried time profiling saving process in instruments?

even if delay entirely within framework code, diving deep time profile can hint of it's doing taking long. example, tangentially related, doing discovered saving uimanageddocuments synced on icloud totally clobbered performance wise presence of inverse relationships in data model.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -