Database Reference
In-Depth Information
Scroll down the page. There's good news and bad news. The good news is that the
app accounts for all six sections. Hooray! The bad news is that the world is upside
down.
Take a closer look at the sections. You'll see Argentina in Africa, Cameroon in Asia
and Russia in South America. How did this happen? It's not a problem with the
data; you can open seed.json and verify that each team lists the correct qualifying
zone.
Have you figured it out? The list of countries is still shown alphabetically and the
fetched results controller is simply splitting up the table into sections as if all teams
of the same qualifying zone were grouped together.
Go back to viewDidLoad and make the following change to fix the problem. Replace
the existing code that creates and sets the sort descriptor on the fetch request with
the following:
let zoneSort =
NSSortDescriptor (key: "qualifyingZone" , ascending: true )
let scoreSort =
NSSortDescriptor (key: "wins" , ascending: false )
let nameSort =
NSSortDescriptor (key: "teamName" , ascending: true )
fetchRequest. sortDescriptors = [zoneSort, scoreSort, nameSort]
The problem was the sort descriptor. This is another NSFetchedResultsController
“gotcha” to keep in mind. If you want to separate fetched results using a section
keyPath , the first sort descriptor's attribute must match the key path's attribute .
 
Search WWH ::




Custom Search