objective c - iOS NSManagedObjectContext - is it possible to get or send a notification when all changes is saved? -


i use core data - , have registered , listening nsmanagedobjectcontextdidsavenotification:s have collection of data (from json), want save, , after objects saved, kind of notification. seems notification sent after every object saved. there kind of built in solution getting desired notification? if not, how could/should it?

there's no built-in notification gets posted after you've saved specific batch of objects. core data has no idea how many objects in collection, has no way know you've reached end of it.

you'll nsmanagedobjectcontextdidsavenotification every time call save: on managed object context. wait save until you've handled of objects, mean 1 nsmanagedobjectcontextdidsavenotification.

a better solution post own notification when know you've finished collection. define string constant called jsonupdatescompletenotification, , post notification name after last save: call.

nsstring *jsonupdatescompletenotification = @"jsonupdatescompletenotification"; 

then later, when know you're done,

[[nsnotificationcenter defaultcenter] postnotificationname:jsonupdatescompletenotification object:self]; 

make sure observe notification anywhere need know it, , you're done.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -