Skip to content

Commit

Permalink
Add shortcut initializers to data sources
Browse files Browse the repository at this point in the history
  • Loading branch information
ishkawa committed Sep 12, 2018
1 parent b2d1dcc commit 1f72c71
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions DataSourceKit/CollectionViewDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ public class CollectionViewDataSource<CellDeclaration>: NSObject, UICollectionVi
return cell
}
}

extension CollectionViewDataSource where CellDeclaration == CellBinder {
// Add meaningless parameter to avoid error `Members of constrained extensions
// cannot be declared @objc`, which is caused by collision to init() of NSObject.
public convenience init(_ declarationType: CellDeclaration.Type) {
self.init(binderFromDeclaration: { $0 })
}
}
8 changes: 8 additions & 0 deletions DataSourceKit/TableViewDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ public class TableViewDataSource<CellDeclaration>: NSObject, UITableViewDataSour
return cell
}
}

extension TableViewDataSource where CellDeclaration == CellBinder {
// Add meaningless parameter to avoid error `Members of constrained extensions
// cannot be declared @objc`, which is caused by collision to init() of NSObject.
public convenience init(_ declarationType: CellDeclaration.Type) {
self.init(binderFromDeclaration: { $0 })
}
}

0 comments on commit 1f72c71

Please sign in to comment.