Database Reference
In-Depth Information
The documentation for NSFetchedResultsController makes this point emphatically,
and with good reason! You saw what happened when the sort descriptor doesn't
match the key path—your data ends up making no sense.
Build and run one more time to verify that this change fixed the problem:
Indeed it did. Changing the sort descriptor restored the geopolitical balance in your
sample application. African teams are in Africa, European teams are in Europe and
so on.
Notes: The only team that may still raise eyebrows is Australia, which
appears under Asia's qualifying zone. This is how FIFA categorizes Australia. If
you don't like it, you can file a bug report with them! ;]
Notice that within each qualifying zone, teams are sorted by number of wins from
highest to lowest, then by name. This is because in the previous code snippet, you
added three sort descriptors: first sort by qualifying zone, then by number of wins,
then finally by name.
Before moving on, take a moment to think of what you'd have needed to do to
separate the teams by qualifying zone without the fetched results controller. First,
you would've had to create a dictionary and iterated over the teams to find unique
qualifying zones. As you traversed the array of teams, you would have had to
associate each team with the correct qualifying zone. Once you have the list of
teams by zone, you'd then need to sort the data.
Of course it's not impossible to do this yourself, but it is tedious. This is what
NSFetchedResultsController saved you from doing. You can take the rest of the day
off and go to the beach or watch some World Cup matches. Thank you,
NSFetchedResultsController !
 
Search WWH ::




Custom Search