Database Reference
In-Depth Information
What happened? NSFetchedResultsController is helping you out here, though it
may not feel like it! If you want to use it to populate a table view and have it know
which managed object should appear at which index path, you can't just throw it a
basic fetch request. The key part of the crash log is this:
'An instance of NSFetchedResultsController requires a fetch request with
sort descriptors'
A regular fetch request doesn't require a sort descriptor. Its minimum requirement
is that you set an entity description, and it will fetch all objects of that type of
entity. NSFetchedResultsController , however, requires at least one sort descriptor.
Otherwise, how would it know the right order for your table view?
Go back to viewDidLoad and add the following lines after you initialize the fetch
request:
let sortDescriptor =
NSSortDescriptor (key: "teamName" , ascending: true )
fetchRequest. sortDescriptors = [sortDescriptor]
Adding this sort descriptor will show the teams in alphabetical order from A to Z
and fix the earlier crash.
Build and run the application. Your screen will look like this:
 
Search WWH ::




Custom Search