Skip to content

Instantly share code, notes, and snippets.

View andreaantonioni's full-sized avatar

Andrea Antonioni andreaantonioni

View GitHub Profile
@andreaantonioni
andreaantonioni / Storyboard.swift
Last active August 29, 2017 19:27
Programmatic reference to storyboards to instantiate view controllers
import Foundation
import UIKit
enum Storyboard: String {
case Main
func instantiate<VC: UIViewController>(_ viewController: VC.Type) -> VC {
guard
let vc = UIStoryboard(name: self.rawValue, bundle: nil)
.instantiateViewController(withIdentifier: VC.storyboardIdentifier) as? VC
@andreaantonioni
andreaantonioni / ios-cell-registration-swift.md
Last active July 15, 2021 13:41 — forked from gonzalezreal/ios-cell-registration-swift.md
iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

A common task when developing iOS apps is to register custom cell subclasses for both UITableView and UICollectionView. Well, that is if you don’t use Storyboards, of course.

Both UITableView and UICollectionView offer a similar API to register custom cell classes:

public func register(_ cellClass: AnyClass?, forCellReuseIdentifier identifier: String)
public func register(_ nib: UINib?, forCellReuseIdentifier identifier: String)