Search and Retrieve Core Data with Criteria
The MythBase examples in Chapters 8 and 9 demonstrated the basics of how Core Data works, letting us create, retrieve, update, and delete objects from a backing store with a minimum of fuss. So far, we’ve been working primarily with full data sets in MythBase. For most of the entities we’ve used (MythicalPerson, MythicalBand, and MythicalVenue), all the objects for each entity are loaded during application startup and kept in memory for the entire life of the application. That’s okay for an application like MythBase, which maintains a small database, but what if one of our main entities consists of thousands or millions of instances in a backing store? Our app would load everything from storage when the app launches, which would probably lead to the app filling up all available memory, swapping to disk, and so on. Apart from that problem, we’d also probably end up with a bad user experience because a GUI that’s navigable when it’s displaying twenty objects in a table view may become impossible to use effectively when there are thousands of entries.