Last active
March 27, 2017 21:45
-
-
Save erica/9dbc9a6b57248b380ec2745adecd0bad to your computer and use it in GitHub Desktop.
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
//: 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