Open sairamsankaran opened 10 years ago
Here is the order of execution. I do not understand why "Request Success" comes lower below and not after "In boxOffice"
2013-10-20 02:17:26.700 rottenTomatoes[76935:a0b] In initWithCoder 2013-10-20 02:17:26.707 rottenTomatoes[76935:a0b] In boxOffice 2013-10-20 02:17:26.737 rottenTomatoes[76935:a0b] In viewDidLoad 2013-10-20 02:17:26.743 rottenTomatoes[76935:a0b] In tableView:cellForRowAtIndexPath 2013-10-20 02:17:26.745 rottenTomatoes[76935:a0b] Movie title from VC: ( ) 2013-10-20 02:17:27.342 rottenTomatoes[76935:a0b] Request Success 2013-10-20 02:17:27.343 rottenTomatoes[76935:a0b] In moviesWithJSON 2013-10-20 02:17:27.343 rottenTomatoes[76935:a0b] Captain Hanks added to data store 2013-10-20 02:17:27.344 rottenTomatoes[76935:a0b] Movie title: Captain Philips
It's because the network request is happening in the background, not on the main thread. That's why you have to pass in a success and failure block. That block of code is called on the main thread after the network request returns.
See Ben's project for a good example of a completed Rotten Tomatoes client: https://github.com/blindsey/RottenTomatoes
Thanks Tim.
Got it working!!! The module part was the most confusing. @timothy1ee
Hi @timothy1ee,
I have attempted to complete the app with the model object. I am facing an issue here. For some reason the update to the model (MovieDataStore) is not visible in the view controller.
I am calling [client boxOffice] in initWithCoder: in the VC. Which in turn calls [MovieDataStore moviesWithJSON:movies];
And then in tableView:(UITableView *)tableView cellForRowAtIndexPath: I am calling [[MovieDataStore sharedStore] boxOfficeMovies] to retrieve the movies.
But in my logs the order of calling the above two is reversed.
2013-10-20 01:50:20.082 rottenTomatoes[76600:a0b] Movie title from VC: ( ) 2013-10-20 01:50:20.752 rottenTomatoes[76600:a0b] Captain Hanks added to data store 2013-10-20 01:50:20.753 rottenTomatoes[76600:a0b] Movie title: Captain Philips
This causes my application to crash. Not quite sure what is happening here.
Any suggestions will be really helpful. Thanks, Sairam