I'm trying to find out exactly what methods (names!) became thread safe in UIKit on iOS 4.0.
I've searched through Apple's docs with little success. For instance a UIImage
created with imageNamed: is not safe to use on other threads (it will occasionally jettison its CGImage
from the main thread), while imageWithCGImage
might be(?). Also, I've seen claims that UIColor
is safe to use on threads other than the main thread.
Is there some definite guide as to which methods are safe which ones isn't?
Edit:
What's interesting is UIKit classes that is interesting to use on separate threads, such as UIImage
, UIColor
etc.
As we can see, most of the components in UIKit is described as nonatomic `, this means there are not thread safe.
In general, immutable classes like NSArray are thread-safe, while their mutable variants like NSMutableArray are not. In fact, it's fine to use them from different threads, as long as access is serialized within a queue.
Loading even a medium-sized image on the main thread will likely take longer than 16.6 milliseconds. Naturally, people identify this as an issue and move image creation to background threads. Generally, the code is based on the assumption that -[UIImage imageWithData:] and -[UIImage imageWithCGImage:] are thread safe.
Each process (application) in OS X or iOS is made up of one or more threads, each of which represents a single path of execution through the application's code. Every application starts with a single thread, which runs the application's main function.
From Apple's documentation:
Note: For the most part, UIKit classes should be used only from an application’s main thread. This is particularly true for classes derived from
UIResponder
or that involve manipulating your application’s user interface in any way.
Therefore, you really shouldn't be interacting with anything in UIKit
on a background thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With