Hey.
I’m somewhat new to Objective-C (for Mac, this is) and I’m writing an app that will open large files, parse them, etc.
Problem is, as the program completes various tasks, I wish to update a progress bar. But the program becomes unresponsive until each task is complete.
How can I get round this?
Thanks.
You’ll want to perform your file I/O and parsing on a background thread. There a few ways to do this within Cocoa/Objective-C, the easiest probably being to use Grand Central Dispatch to perform the action with
dispatch_async()or a similar function. There are lots of questions related to performing tasks using GCD around SO, and here and here are good places to start.As can be seen in the second article, there are ways of setting up completion blocks that will perform UI actions on the main thread when a given operation finishes in a dispatch thread.