I'm learning socket communication on iPhone, and its guide said something about CFRunloop
(it is a guide for CFNetwork
, can this be used on iOS?)
Where can I learn about runloop on iOS?API reference is not enough.
Look at the "Run Loops" chapter of Apple's Threading Programming Guide. In brief:
One major pitfall is forgetting to run the run loop while waiting for a callback from a runloop source. This is sometimes a problem when you decide to busy-wait for something to happen on the main thread, but you're most likely to run into it when you create your own thread and register a runloop source with that runloop. You are responsible for establishing an autorelease pool and running the runloop if needed on non-main threads, since the application main function will not be there to do it for you.
You would do better to read Apple's Concurrency Programming Guide instead, which suggests alternatives to the runloop mechanism such as operation queues and dispatch sources. The "Replacing Run-Loop Code" section of the "Migrating Away from Threads" chapter suggests using dispatch sources instead of runloop sources to handle events.