@@ -29,7 +29,7 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega
2929 fetchRequest. sortDescriptors = [ sortDescriptor]
3030
3131 // Initialize Fetched Results Controller
32- let fetchedResultsController = NSFetchedResultsController ( fetchRequest: fetchRequest, managedObjectContext: context, sectionNameKeyPath: nil , cacheName: nil )
32+ let fetchedResultsController = NSFetchedResultsController ( fetchRequest: fetchRequest, managedObjectContext: context, sectionNameKeyPath: " sectionCriteria " , cacheName: nil )
3333
3434 // Configure Fetched Results Controller
3535 fetchedResultsController. delegate = self
@@ -59,16 +59,22 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega
5959 if let sections = fetchedResultsController. sections {
6060 return sections. count
6161 }
62-
6362 return 0
6463 }
6564
65+ func tableView( tableView: UITableView , titleForHeaderInSection section: Int ) -> String ? {
66+ if let sections = fetchedResultsController. sections {
67+ let currentSection = sections [ section]
68+ return currentSection. name
69+ }
70+ return nil
71+ }
72+
6673 func tableView( tableView: UITableView , numberOfRowsInSection section: Int ) -> Int {
6774 if let sections = fetchedResultsController. sections {
6875 let sectionInfo = sections [ section]
6976 return sectionInfo. numberOfObjects
7077 }
71-
7278 return 0
7379 }
7480
@@ -77,7 +83,6 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega
7783
7884 // Configure Table View Cell
7985 configureCell ( cell, atIndexPath: indexPath)
80-
8186 return cell
8287 }
8388
0 commit comments