Note that there are some explanatory texts on larger screens.

plurals
  1. POAFJSONRequestOperation array populates but cannot NSLog contents outside of success block
    primarykey
    data
    text
    <p><a href="http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_afnetworking/" rel="nofollow">The following code is taken from this tutorial</a></p> <p>I've used this snippet before but I never noticed this issue before. NSLog of the array contents prints in a delegate method but not in the viewDidLoad outside of the success block. I require a way to save the JSON data into an array for use elsewhere in the code. I should also add that I'm not using UITableView to display my data. What am I missing or how can I accomplish this? </p> <p><strong>This does not print the JSON content thought it does populate the array:</strong></p> <pre><code>#import "AFNetworking.h" ... - (void)viewDidLoad { ... self.movies = [[NSArray alloc] init]; NSURL *url = [[NSURL alloc] initWithString:@"http://itunes.apple.com/search?term=harry&amp;country=us&amp;entity=movie"]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { self.movies = [JSON objectForKey:@"results"]; [self.activityIndicatorView stopAnimating]; [self.tableView setHidden:NO]; [self.tableView reloadData]; } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo); }]; [operation start]; NSLog(@"self.movies %@",self.movies); // does not print ... } </code></pre> <p><strong>This does print the JSON content:</strong> I've only used numberOfRowsInSection as a separate location for the NSLog statement.</p> <pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (self.movies &amp;&amp; self.movies.count) { NSLog(@"self.movies %@",self.movies); // prints ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload