Created
May 31, 2016 12:26
-
-
Save finneycanhelp/9a9f7c299582bd70bfe8ab1965d96d93 to your computer and use it in GitHub Desktop.
Showing Why associatedtype had to conform
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 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) | |
} | |
} |
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
ok. Title should be. Why associatedtype had to ensure it inherited Object. ha ha