Cocoa-Touch – Guidelines on what thread to perform GUI updates

I know as a general guideline you should always perform GUI updates on the main thread. But sometimes it's not that obvious. E.g where should I perform the calls:

setBadgeValue: of a UITabBarItem?

Or

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]

In the class reference it's not specified whether these methods can be run on a non-main thread.

Answers


The general rule is that you should keep UIKit updates to the main thread, unless UIKit calls through your implementation from another thread.

Reference: Important: The UIKit classes are generally not thread safe. All drawing-related operations should be performed on your application’s main thread.

From iOS 4 release notes:

  • Drawing to a graphics context in UIKit is now thread-safe. Specifically: The routines used to access and manipulate the graphics context can now correctly handle contexts residing on different threads.
  • String and image drawing is now thread-safe.
  • Using color and font objects in multiple threads is now safe to do.

With that information, and unless I or somebody else digs up more docs (which I scanned release notes and saw no more):

setBadgeValue: of a UITabBarItem?

Assume it is safe to call only from the main thread.

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]

Assume it is safe to call only from the main thread.


Need Your Help

SQL query for field content containing whole words that begin with PHRASE

sql ruby-on-rails meta-where

I am trying to write a SQL query to fetch rows whose fields contain multiple key words. The use for the query is to fetch results for an autocompleter function implemented with jQuery.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.