continue in main thread after block has executed.

my call makes a call to HKSampleQuery method initWithSampleType that queries information from healthkit store. I want the main thread to wait until the the query is over so that the block handler updates the global variables in the custom class.


I understand concurrency but haven't used it enough. Please help me with this one.


my code goes like this...


[self methodone];
do something based on result

-(void)methodone
{
api call with blockhandle
{ set result to global variables in block};

}
Answered by ace.neerav in 643449022
The path I took was to dispatch asynchronously on the main thread a notification which would carry the data on a dictionary.

Let's clear up an issue. In your code will you please add the NSLog line in this:


    appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];  
    HKHealthStore *store = [[appDelegate hkOperator] hkStore];   
    NSLog(@"going to execute the query NOW");
    [store executeQuery:query]; 


Then run and tell us whether it printed "going to execute the query NOW" before it printed your "Quantity: " and how often it printed your "Quantity: " and what values it gave for your quantity?

Accepted Answer
The path I took was to dispatch asynchronously on the main thread a notification which would carry the data on a dictionary.
continue in main thread after block has executed.
 
 
Q