Last active
          March 17, 2016 16:46 
        
      - 
      
 - 
        
Save krodak/25680b1ec18e750f6ddd to your computer and use it in GitHub Desktop.  
    UICollectionView+dequeue
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | extension UICollectionView { | |
| public func dequeueReusableCell<T:UICollectionViewCell>(type: T.Type, indexPath: NSIndexPath) -> T { | |
| let collectionCell : T | |
| let cellIdentifier = String(T) | |
| if let _ = NSBundle(forClass: T.classForCoder()).pathForResource(cellIdentifier, ofType:"nib") { | |
| registerNib(UINib(nibName: cellIdentifier, bundle: nil), forCellWithReuseIdentifier: cellIdentifier) | |
| collectionCell = dequeueReusableCellWithReuseIdentifier(cellIdentifier, forIndexPath: indexPath) as! T | |
| } | |
| else { | |
| collectionCell = T() | |
| } | |
| return collectionCell | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment