Database Reference
In-Depth Information
CHAPTER 5
Threading
Multithreading is one of the great double-edged swords of programming. If it
is done correctly, it can be a real boon to your application; done incorrectly,
it leads to strange, unreproducible errors in the application. Multithreading
has a tendency to polarize developers: they either swear that it is necessary
for any application to perform properly or declare it is to be avoided at all
costs. The truth, of course, is somewhere in the middle. Multithreading is a
vital piece of the overall performance puzzle. While adding more threads will
not make your application automatically faster, it can make your application
“feel” faster to the user. That perception is what we are going to focus on in
this chapter.
The problem is that Core Data is not inherently thread-safe. It still wants and
expects to be run in a single thread. Therefore, when we start multithreading
our applications, we must take care to work with Core Data properly to avoid
threading issues. Fortunately, as of iOS 6.0 and OS X 10.8 Mountain Lion,
things have improved significantly.
Core Data and iOS 5.0
As mentioned in the introduction, we are focusing primarily on iOS 6.0. However, in
this chapter in particular, many of the APIs discussed were actually introduced in
iOS 5.0 (as well as OS X 10.7 Lion). Unfortunately, while the APIs were introduced
at that time, they didn't work very well. In some cases, they didn't work at all.
Therefore, it is my recommendation to treat iOS 5. x as if it were iOS 4. x and to avoid
using any of the Core Data APIs that were introduced in 5.0.
5.1
Why Isn't Core Data Thread-Safe?
You may be surprised to learn that there are a lot of things in Cocoa and
Objective-C that are not thread-safe, and Core Data is only one of the many.
 
 
 
Search WWH ::




Custom Search