Question on -mergeChangesFromContextDidSaveNotification:


#1

Hi,
On page 564, first paragraph mentions: [quote]BNRFeedStore is told to perform the merge on a background thread, so the notification will be posted and received on a background thread as well.[/quote]

Performing on a background thread makes sense, but I’m curious as to know if there’s a steadfast rule to determine whether a method/operation is being performed on the main thread or a background thread.

Thanx in advance!


#2

It is one of those things that SHOULD be documented in the documentation, but isn’t always.

The way I came to find out was that I noticed the table view wasn’t updating very quickly. At first, I thought it was because the changes might take awhile to sync with the server, so I put an NSLog before and after the Core Data call to perform the merge. Turns out, the merge was completing well before the table view was reloaded. Which led me to the next piece of information: the table view was being told to reload and it took nearly 5 seconds for the table view to appear reloaded. The application couldn’t have been stalling during the reloadData method, because it was responding to events. Thus, the reloadData must have been happening on another thread. I logged the currentThread and the mainThread from within the method that performed the merge and sure enough, the notification was being delivered on a different thread.

Most of the time, the documentation will tell you. Other times, you might have to sense around a bit. You can check out NSThread to see some important methods for determining this stuff.


#3

Hi, Joe. Great book! (I just finished it yesterday.) I don’t know if you’re still monitoring this thread, but does your intuition and experience suggest to you what other parts of the framework might also use posting of notifications in a background thread? Is this widespread, or is this something that only goes on in the dark corners of the framework. Any idea what might make Apple make a choice like this? (I’m not criticizing their choice; I’m just trying to get a sense of the underlying design logic so that I might be able to identify any problems I might run into in the future.)

In other words, having gotten your two cents, I’m looking for two bits more :wink:

Thanks.


#4

If they do post it on another thread, the documentaiton will be clear. In this case, I am sure there was some drawback to posting it on the main thread