I am using a framework to get information from the network. The pr开发者_运维技巧oblem is the function I'm using to get the information is threaded (ie. it gives information through a didFinish selector, not the actual function as the return value).
I want to create a separate NSThread that uses this threaded function. The problem is if I detach a thread, it won't wait for the information from this threaded function (and it doesn't know when the information is sent back).
Is there a way to fix this situation? In a nutshell, I want to turn an asynchronous function into a synchronous function.
You'll want to read up on NSRunLoop and the Threading Programming Guide
I think the basic approach will be something like this:
- In your detached thread main body
- set yourself as a custom input source to the runloop
- while your state is not done, run the runloop
- In
didFinish:
- set some state that says you're done
- tell the runloop that the input source (yourself) fired
精彩评论