Skip to content

Instantly share code, notes, and snippets.

@efremidze
Created August 17, 2017 23:01
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 efremidze/a617b0af36c37b79f98effa945a0bedb to your computer and use it in GitHub Desktop.
Save efremidze/a617b0af36c37b79f98effa945a0bedb to your computer and use it in GitHub Desktop.
class Cell: UICollectionViewCell {
@IBOutlet weak var imageView: UIImageView!
private static var sharedInstance: Cell!
static func makeCell(width: CGFloat) -> Cell {
if sharedInstance == nil {
sharedInstance = UINib(nibName: String(describing: Cell.self)).instantiate(withOwner: nil, options: nil).first as! Cell
sharedInstance.constrain { [$0.imageView.widthAnchor.constraint(equalToConstant: width)] }
}
return sharedInstance
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment