Last active
October 27, 2020 13:27
-
-
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
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 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