Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save finneycanhelp/9a9f7c299582bd70bfe8ab1965d96d93 to your computer and use it in GitHub Desktop.
Save finneycanhelp/9a9f7c299582bd70bfe8ab1965d96d93 to your computer and use it in GitHub Desktop.
Showing Why associatedtype had to conform
import Foundation
import RealmSwift
import SwiftFetchedResultsController
protocol FetchedResultsControllerTableViewDataSource: class {
associatedtype T : Object
var fetchedResultsController: FetchedResultsController<T>? { get set }
func numberOfSectionsInTableView(tableView: UITableView) -> Int
}
extension FetchedResultsControllerTableViewDataSource where Self: UITableViewDataSource {
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return self.fetchedResultsController!.numberOfSections()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.fetchedResultsController!.numberOfRowsForSectionIndex(section)
}
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return self.fetchedResultsController!.titleForHeaderInSection(section)
}
}
@finneycanhelp
Copy link
Author

ok. Title should be. Why associatedtype had to ensure it inherited Object. ha ha

@finneycanhelp
Copy link
Author

This compiled but didn't work when placed into place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment