Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-blocking wait function in Objective-C

Tags:

objective-c

I'm fairly new to Objective-C and I can't figure out how to wait in a non-blocking manner. I have an object that is being populated asynchronously and I need to wait on it before I can proceed in another method. Right now I am using the sleep function, but this blocks the whole app and myObject never gets loaded.

while (!myObject)
{
    sleep(1);
}
return myObject;

EDIT: This code snippet is from a method that may be called before myObject has been loaded. In this case I actually do want to block in this method, but my code blocks everything including myObject from being loaded.

like image 873
Stefan Moser Avatar asked Jul 17 '09 17:07

Stefan Moser


1 Answers

This little peach worked for me (in-order to delay for 20 seconds)....

CFRunLoopRunInMode(kCFRunLoopDefaultMode, 20.0, false);
like image 56
Oliver Pearmain Avatar answered Oct 15 '22 22:10

Oliver Pearmain