PDA

View Full Version : NSOperation and asynchronous calls




idelovski
Apr 28, 2011, 04:12 PM
I have a NSOperation that downloads a file from the web server, converts it and then stores result into a SQLite database. Now I need to add Dropbox support and all of their download calls are asynchronous.

Should I break my operation into stages? This would be a major pain in the neck right now. Or maybe I can turn Dropbox asynchronous methods into synchronous by creating new method that starts download, waits in a loop for some flag while doing NSThread-sleepForTimeInterval: and then returning when the file is ready?

Anyone doing a similar thing?

EDIT:

Luckily for me, I haven't done a single thing about this problem since yesterday. So I overslept it and know I now how to proceed. My operation defines almost a dozen delegate methods and I was afraid I would need to break these into two different delegate protocols, but now is obvious I don't need to change much about almost anything.

When I need a file from Dropbox, I use asynchronous Dropbox API to first bring the file to the local directory and my NSOperation starts from there. All I need is two initialization methods, one that uses URL, which I already have and another that I need to create that receives a path as parameter. Case solved.