1

I have an viewController that fires a web service get some data and stores the result in core data after parsing in a different thread..

I have a lot of data so parsing will take some time and am not sure if popping the viewController in navigation will stop the execution of my parsing method,

if it stops the execution in between then my core data DB will get corrupted so does it stops the execution or perform the selector before releasing my viewController object

MyViewController *vc = [[MyViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
[vc performSelectorInBackground:aSelector withObject:arg];
Yogesh Maheshwari
  • 1,324
  • 2
  • 16
  • 37
  • Are you using ARC? If not, where is `MyViewController` released? Is it autoreleased? – Romain Apr 25 '12 at 13:41
  • 1
    If the parsing is in a different thread, it shouldn't be affected. If you have a callback or notification that goes back to your view controller when the parsing is done, that could be a problem. If data corruption is a serious problem, you should also consider the user pressing the home button. – Phillip Mills Apr 25 '12 at 13:46
  • Nice point Phillip, I wasn't even considering that as a problem, do you have any suggestion?? – Yogesh Maheshwari Apr 27 '12 at 05:52

1 Answers1

3

You might consider moving the web server interactions to a different object. This object could handle the requests / responses and storing the results to Core Data. This object might also be a global object with a queue to handle requests. If not then you will need to handle canceling the request during your view controller dealloc.

Your view controllers can listen for changes to Core Data and take appropriate action.

bbarnhart
  • 6,620
  • 1
  • 40
  • 60
  • and the connection thingy can keep track of inflight requests count, throttling if needed. +1 for pointing out that core data should be observed for changes, rather than notifications or delegate (yuck!). – danh Apr 25 '12 at 14:32
  • What do you mean by "listen for changes to Core Data", as far as i know you listen to contextdidsavenotification and take appropriate action, is there any other way?? – Yogesh Maheshwari Apr 27 '12 at 15:27
  • 1
    Get a notification when Core Data changes. [Check out this SO Link](http://stackoverflow.com/questions/2463950/iphone-coredata-how-can-i-track-observe-all-changes-within-a-subgraph) – bbarnhart Apr 27 '12 at 17:38