TableViewDataSource
public class TableViewDataSource<Delegate: TableViewDataSourceDelegate>: NSObject,
UITableViewDataSource,
NSFetchedResultsControllerDelegate
A data source for a UITableView that relies on a NSFetchedResultsController for model values. This design was heavily based on code from obj.io Core Data book.
-
Undocumented
Declaration
Swift
public typealias Entity = Delegate.Entity -
Undocumented
Declaration
Swift
public typealias Cell = Delegate.Cell -
Obtain the managed object for the currently selected row
Declaration
Swift
public var selectedObject: Entity? { get } -
Construct a new instance.
Declaration
Swift
public required init( tableView: UITableView, cellIdentifier: String, fetchedResultsController: NSFetchedResultsController<Entity>, delegate: Delegate )Parameters
tableViewthe UITableView that will show the rendered model instances
cellIdentifierthe identifier of the UITableViewCell to use for rendering
fetchedResultsControllerthe source of model instances from Core Data
delegatethe delegate for rendering and deletion handling
-
Obtain the number of model instances, or the number of rows in the UITableView.
Declaration
Swift
public var count: Int { get } -
Obtain the model instance for a given UITableView row.
Declaration
Swift
public func object(at indexPath: IndexPath) -> EntityParameters
indexPaththe row to fetch
Return Value
the found model instance
-
Change an existing Core Data fetch request and execute it.
Declaration
Swift
public func reconfigureFetchRequest(_ configure: (NSFetchRequest<Entity>) -> Void)Parameters
configureblock to run to edit the request
-
Query for the number of rows in a table view section.
Declaration
Swift
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> IntParameters
tableViewthe UITableView being asked about
sectionthe section being asked about
Return Value
row count in the section
-
Obtain a formatted UITableViewCell for a specific row in a table view. The delegate’s
configuremethod performs the necessary configuration on the cell before it is used.Declaration
Swift
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCellParameters
tableViewthe UITableView being worked on
indexPaththe index of the row being displayed
Return Value
the UITableViewCell to use to display the row
-
Query to find out if a row in a table view can be edited.
Declaration
Swift
public func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> BoolParameters
tableViewthe UITableView being worked on
indexPaththe index of the row being asked about
Return Value
true if so
-
Perform an edit action on a specific row
Declaration
Swift
public func tableView( _ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath )Parameters
tableViewthe UITableView being worked on
editingStylethe operation being performed. The only one supported is
.deleteindexPaththe index of the row being edited
-
Notification from NSFetchedResultsController that it is is going to make changes that affect the view
Declaration
Swift
public func controllerWillChangeContent( _ controller: NSFetchedResultsController<NSFetchRequestResult> )Parameters
controllerthe controller performing the work
-
Notification from NSFetchedResultsController about a change at a given index.
Declaration
Swift
public func controller( _ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath? )Parameters
controllerthe controller performing the work
anObjectthe object being affected
indexPaththe index of the object being affected
typethe type of change being performed
newIndexPaththe new index of the object after the operation (optional)
-
Notification from NSFetchedResultsController that all changes are done. Notify the delegate that the view was changed.
Declaration
Swift
public func controllerDidChangeContent( _ controller: NSFetchedResultsController<NSFetchRequestResult> )Parameters
controllerthe controller that performed the work
View on GitHub
TableViewDataSource Class Reference