views:

420

answers:

1

I have multiple NSURLConnections running providing data back to the delegate objects. Is it safe for these delegate objects all to store their data into a single instance of an sqlite database connection?

ie Do the callbacks to the delegates come back in on different threads?

+3  A: 

The delegate methods are fired in whichever thread's run loop you scheduled the download in, i.e. they occur in whichever thread you started the download off in. From the documentation:

Note that these delegate methods will be called on the thread that started the asynchronous load operation for the associated NSURLConnection object.

That means that the answer to the question "do [they] come back in on different threads?" depends on the design of your app. If you launched them all in one thread, then no.

Graham Lee
Er? If you launched them all on one thread, they should all come back in on that one thread. If you launched each one on a separate thread, then each will come back on the same thread you launched it on.
Peter Hosey
Peter: only an off-by-one error... :-)
Graham Lee