Re: Showing activity indicator during data download
Re: Showing activity indicator during data download
- Subject: Re: Showing activity indicator during data download
- From: Alastair Houghton <email@hidden>
- Date: Thu, 29 Oct 2009 16:00:42 +0000
On 29 Oct 2009, at 15:08, DKJ wrote:
On 2009-10-29, at 7:05 , Alastair Houghton wrote:
You need to rewrite your code so that the download is asynchronous.
Would doing the NSOperationQueue thing with my updateDataFiles
method be OK? The docs (Appendix A of "Threading Programming Guide")
lists NSString as being thread-safe.
If you insist on using threading, then yes, you could do this in the
background with an NSOperationQueue (or by using NSThread directly).
As for Foundation objects and thread-safety, note that immutable
objects generally *are* thread-safe, but mutable ones generally
aren't. So NSString is, but NSMutableString isn't.
To be honest, it's going to be easiest just to use the asynchronous
NSURLConnection approach. It really isn't that hard (honest); for the
most part it just means that part of your code turns into a state
machine. The best part, though, is that you don't have to worry about
thread safety.
Finally, some (hopefully) useful advice:- If you're writing code that
uses an asynchronous approach like this, it's often easiest to hive
the resulting state machine off into a separate object and use that
object as the delegate of the NSURLConnection. While you'll still
need to send messages back to your original object, doing things this
way isolates the code in the same way that writing a separate function
does.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden