Reputation: 681
I need to make a call getValuesAndCalculate
in my app, which should return only after doing its work. However, for doing its work, it needs to get records from a server, which has to be done through an async call. The server data is received through a callback function. Thus, in getValuesAndCalculate
I need to wait till I have the data before proceeding with the calculations. How do I implement this?
Upvotes: 0
Views: 1368
Reputation: 426
You can implement Threads for this question i.e,
// in main thread
// start activity indicator
NSThread *calculateThread = [[NSThread alloc] initWithTarget:self selector:@selector(getValuesAndCalculate) object:nil];
[calculateThread start];
// End of Main thread
- (void)getValuesAndCalculate
{
// Perform transactions with server
[self performSelectorOnMainThread:@selector(continueMainThreadOperations) withObject:nil waitUntilDone:YES];
}
Thats it!
Upvotes: 0
Reputation: 1528
Try using NSRunloop till you get the data from the server.
For eg :
while (!isFinished) { [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:1.0] }
Upvotes: 0
Reputation: 2186
delegates are nothing but you assigning an object from your class to a object on the server side . The server can use this object to call a method on your client side code.
Upvotes: 2