Skip to content

Instantly share code, notes, and snippets.

@josipbernat
Last active October 27, 2020 13:27
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 josipbernat/2f9c740887353b41752c16e794cdb6e3 to your computer and use it in GitHub Desktop.
Save josipbernat/2f9c740887353b41752c16e794cdb6e3 to your computer and use it in GitHub Desktop.
Easy accessing UIView XIBs when XIB file has the same name as class
extension UIView {
//MARK: - XIBs
// https://stackoverflow.com/questions/24857986/load-a-uiview-from-nib-in-swift
public class var nibName: String {
let name = "\(self)".components(separatedBy: ".").first ?? ""
return name
}
public class var nib: UINib {
return UINib.init(nibName: nibName, bundle: nil)
}
}
// When you need to register UITableViewCell / UICollectionViewCell
// collectionView.register(MyCollectionCell.nib, forCellWithReuseIdentifier: "CellIdentifier")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment