iphone - Core Data Saves and UI Performance -


Text after "

If there is a saving of core data with large collection (not fetch) while doing any to improve UI responsiveness Best Practices I'm Thinking of Managed Items

The app that I'm working on, until it is complete, requires a large amount of data to be downloaded from the web service at a given interval. At each interval, download the batch of data Done, formatted in managed object, and saved in core data. Because this process sometimes completes for 5 minutes completely, until it is completely complete, till the time of adding the loading screen, everything does not end, it is not really an option, It takes a very long time. Instead of writing a bigger note to my memory footprint at the end, I'm often interested in writing core data. Ideally, I like the user generally using the rest of the application, while downloading together and Want to be able to keep writing these large data sets to core data.

Unfortunately, what is happening is that when I put in the managed object context for your inserts try to save that I each batch, then you balance the user to save the operation Prevents the app from interacting with other numbers, touch buttons, etc. For a brief period of time, where a core data is being saved, the application is very unresponsive.

Naturally, I have tried to create interval differently by reducing the size of the different batches that are downloaded per second, but in addition to the inconvenience of making the whole process, still at such time When the user does not have a swipe capture, because one core data was saved at that particular time. By reducing the size it is less likely that the missed swipe or missed touch will occur, but they still seem adequately in order to be inconvenient.

own investor, I have two different implementations: insertNewObjectForEntityForName: both Valuforkesvidthiasn set with inManagedObjectContext showed the problem went above

I perform both Simulator and device Tried to prototype a very simple test to see, I have provided important elements here. This example does not actually download anything from the web, but just a h Ika set within view controller writes a whole bunch of stuff for the main data gaps. . I'll be happy to hear any suggestions to improve a responsiveness that

  - (minus) viewDidAppear: (bool) animated {[super viewDidAppear: animated]; Timer = [NSTimer Scheduled Timer with Time Interval: 1 Goal: Self Selector: @Selector (doTimerWork :) userInfo: Zero repeats: Yes]; } - (void) doTimerWork: (id) The {(int i = 0; i & lt 1000; i ++ to {Miscellaneous * m = (Miscellaneous *) to) [NSEntityDescription insertNewObjectForEntityForName: @ "Miscellaneous" inManagedObjectContext: managedObjectContext] ; M.someDate = [NSDT Date]; M.somestring = @ "ASDASDASD"; M.someOtherString = @ "Bala Blah Blah"; M.someNumber = [NSN Numbers: 5]; M.someOtherNumber = [NSNumber NumberAttro: 99]; M.sometherdate = [NSDT date]; } NSError * error; If (! [ManagedObjectContext save: & amp; Error]) {NSLog (@ "An error occurred while saving the core data"); }}  

"itemprop =" text ">

It looks like you need to remove the deep stuff with your data < em> core data on a separate thread, which is very easy in Cocoa fortunately you can simply do:

  [obj performSelectorInBackground: @selector (method :) withObject: Arg];  

and then design things so that once data is complete intensive operation, please call:

  [other object execution Cynkrtaonmainthred: @ selector (Detastafaisdion :) With Object: Arg Wait: No];  

At which point you can update your UI

The main thing to remember is always to design your own Put the UI logic on the main thread , and if you do anything with the code, then there may be very strange things> UIKit from a different thread, because this thread is safe Has not been designed for.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -