I’m developing an iOS app which includes a search form. When a user clicks search, I want to use an NSInvocationOperation (which is fine) to spawn another thread. On this thread, I’ll call my data layer (a separate class) to retrieve data from a web service. Is there any way I can pass the data layer a method in my ViewController subclass which should be executed on completion, along with the other arguments (search term etc)? Kind of like .NET’s BackgroundWorker?
Share
Sounds like a case for Blocks (iOS4+). There’s quite a nice tutorial here and excellent documentation from Apple here. Blocks are perfect when you want to kick off an asynchronous task and pass in details of what to do when it has finished, so could well be appropriate in your case.