I’m trying program something very similar to iPhone’s Clock application. In Clock.app, when you add a new World Clock, a modal view appears for searching and adding new cities. While I can get this functionality, I have a long delay before displaying the modal.
I’ve implemented the modal view, the search bar, and the tableview. I’ve created a plist with an array of dictionaries of over 1,000 cities and their corresponding states, like so:
<dict>
<key>City</key>
<string>Chicago</string>
<key>State</key>
<string>Illinois</string>
</dict>
<dict>
...
</dict>
My problem appears on the modal views’s viewWillAppear when I parse the plist into an array of “City” objects using a for loop. The parsing and searching works, but this loop creates a long delay before the modal sides up.
Is there a better way to do this? Maybe using CoreData, multiple threads, GCD? I’m a beginner, so I’m not sure what the best option is. Thanks!
Its always better to do any long-running operation in the background. On iOS there are a number of ways to do that. If you are able to limit to iOS 4+, then dispatch queues are a great way to go. Otherwise, you can go with an NSOperationQueue.