views:

172

answers:

2

Does iPhone OS distinguish between foreground and background threads?

+1  A: 

[NSThread isMainThread]

Phil Nash
+5  A: 

There is the notion of the main thread, where all UIKit and Core Graphics calls have to come from. I suppose you could say the main thread is a foreground thread and all other threads in your app are background threads.

You can start a background thread with performSelectorInBackground:withObject: on NSObject. If you need to do some work on the main thread (eg. do some UI stuff), you can use performSelectorOnMainThread:withObject:waitUntilDone:. If you need to check if your code is currently running on the main thread, you can use [NSThread isMainThread].

Will Harris