Skip to content

Instantly share code, notes, and snippets.

@erica
Last active March 27, 2017 21:45
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 erica/9dbc9a6b57248b380ec2745adecd0bad to your computer and use it in GitHub Desktop.
Save erica/9dbc9a6b57248b380ec2745adecd0bad to your computer and use it in GitHub Desktop.
//: Playground - noun: a place where people can play
import UIKit
public protocol Constructible {
init()
}
public final class MyDataSource<T: Constructible>: NSObject, UICollectionViewDataSource {
var x = T()
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
return UICollectionViewCell()
}
}
public class MyCollectionViewController<T: Constructible>: UICollectionViewController {
public override func viewDidLoad() {
super.viewDidLoad()
collectionView?.dataSource = MyDataSource<T>()
}
}
public func doSomethingWithVC<T>(vc: MyCollectionViewController<T>) {
}
extension String: Constructible {}
let vc = MyCollectionViewController<String>()
doSomethingWithVC(vc: vc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment