Can't work with data from NSURLSession on main thread
<p>I put network session code in viewDidLoad. And I configured session to be executed in main queue. In completion handler I save received data to class property.
Than after [dataTask resume] operation, I want to start processing and analyse this property, but from NSlog result I can see, that is empty.
So as I understand it's empty because block with processing network data is still being executed when I try to print my property, even though I configured session to main queue. What should I change to make it work properly?</p>

<p>Code:</p>

<pre><code>@interface MainSourceDailyViewController ()
@property (strong, nonatomic) NSArray *allData;

@end

@implementation MainSourceDailyViewController

- (void)viewDidLoad {
[super viewDidLoad];


NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]
                                                      delegate:nil
                                                 delegateQueue:[NSOperationQueue mainQueue]];
NSURL *url = [NSURL URLWithString: @"http://xxxxxxxxxx"];

NSURLSessionDataTask * dataTask = [session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

    NSArray *array = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

    if ([[NSThread currentThread] isMainThread]){
        NSLog(@"In main thread--completion handler");
    }
    else {
        NSLog(@"Not in main thread--completion handler");
    }
    self.allData = [[NSArray alloc] initWithArray:array];
    NSLog(@"Answer in block: %@", self.allData);


}];
[dataTask resume];

NSLog(@"Final answer %@", self.allData);
</code></pre>

<p>}</p>

<p>Output:</p>

<pre><code>2016-05-15 01:20:55.359  Final answer (null)
2016-05-15 01:20:56.500  In main thread--completion handler
2016-05-15 01:20:56.506  Answer in block: (
    {
Data contents
},
</code></pre>