Created
July 11, 2016 14:36
-
-
Save danielgarbien/b2c38b9f8a2517bf7d5916732eb6a0c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import UIKit | |
import CoreData | |
class FetchedResultsTableDataSource: NSObject { | |
typealias CellForRowAtIndexPath = (tableView: UITableView, indexPath: NSIndexPath, object: AnyObject) -> UITableViewCell | |
let fetchedResultController: NSFetchedResultsController | |
private let cellForRowAtIndexPath: CellForRowAtIndexPath | |
init(fetchedResultController: NSFetchedResultsController, cellForRowAtIndexPath: CellForRowAtIndexPath) { | |
self.fetchedResultController = fetchedResultController | |
self.cellForRowAtIndexPath = cellForRowAtIndexPath | |
} | |
} | |
extension FetchedResultsTableDataSource: UITableViewDataSource { | |
func numberOfSectionsInTableView(tableView: UITableView) -> Int { | |
return fetchedResultController.sections?.count ?? 0 | |
} | |
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return fetchedResultController.sections?[section].numberOfObjects ?? 0 | |
} | |
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { | |
let object = fetchedResultController.objectAtIndexPath(indexPath) | |
return cellForRowAtIndexPath(tableView: tableView, indexPath: indexPath, object: object) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment