I figured out what was going on with the connections not working in
NSThread and NSOperation. It turns out that using a delegate makes the
app unstable half the time and when the response data is returned your
app can crash in apple's code reading the stream in in the Core
Foundation levels of the OS. For the record NSOperation and NSThread
can both be used very well for both authenticated and non-
authenticated url connections as well as for regular computational
threads. The problem was that I wasn't using sendSyncrhonousRequest on
the 2nd thread to make the callout to del.icio.us in making the
connection.
My best guess is that doing anything else isn't thread safe, thus
leading to app instability. Although I can't find specific mention of
this in the documentation which would be helpful if Apple noted this
(if true.) I've implemented a mini Del.icio.us client using both
NSThread and NSOperation with the source code attached to this
message. My only gripe in the examples is that In the NSOperation
example calling performSelectorOnMainThread doesn't actually make a
call on the main thread but instead (inside NSOperation) makes a call
to itself with the selector you provide. To get around this I had to
make AppController a shared instance and make the
performSelectorOnMainThread call on the shared instance which isn't
very good, but is better than nothing.
In fact I just got done with a chat with Marcus Zarra (of Cocoa is my
Girlfriend / seSales and iWebBuddy ) about this.
Anyway just remember not to use sendSynchronousRequest on the main
thread at any time as it blocks whatever thread made the call to the
synchronousRequest (per Apple Documenation http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html#/
/apple_ref/occ/clm/NSURLConnection/
sendSynchronousRequest:returningResponse:error: )
Enjoy and feel free to comment on my code (good and bad). Thanks!
Colin Wheeler
http://code.google.com/p/redflag/
http://groups.google.com/group/redflag-project