Skip to content

Instantly share code, notes, and snippets.

@Iron-Ham
Last active May 15, 2017 23:05
Show Gist options
  • Save Iron-Ham/60cb138440c551f32a884b979f04e26b to your computer and use it in GitHub Desktop.
Save Iron-Ham/60cb138440c551f32a884b979f04e26b to your computer and use it in GitHub Desktop.
A better way!
// Instantiating view controllers from a storybaord
let myStoryboard: UIStoryboard = ...
let myCustomViewController: MyCustomViewController = myStoryboard.instantiateViewControllerOfType(MyCustomViewController.self)
// Registration of a UITableViewCell
tableView.register(MyCustomCellType.self)
// Dequeueing of a UITableViewCell
let cell = tableView.dequeueReusableCell(for: indexPath) as MyCustomCellType
// Registration of a UICollectionViewCell
collectionView.register(MyCustomCellType.self)
// Dequeueing of a UICollectionViewCell
let cell = collectionView.dequeueReusableCell(for: indexPath) as MyCustomCellType
// Registration of a UITableViewHeaderFooterView
tableView.register(MyCustomHeaderFooterView.self)
/// Dequeueing of a UITableViewHeaderFooterView
let header = tableView.dequeueReusableHeaderFooterView(inSection: section) as MyCustomHeaderFooterView
// Registration UICollectionView Supplementary View
collectionView.register(MyCustomSupplementaryView.self, forSupplementaryViewElementOfKind: .sectionHeader) // or .sectionFooter
// Dequeueing UICollectionView Supplementary View
let view = collectionView.dequeueReusableSupplementaryView(ofKind: .sectionHeader, for: indexPath) as MyCustomSupplementaryView // also takes .sectionFooter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment