Skip to content

Instantly share code, notes, and snippets.

@fernandomatal
Last active August 31, 2019 04:32
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 fernandomatal/fccde2ab82173431241d6323b47b4576 to your computer and use it in GitHub Desktop.
Save fernandomatal/fccde2ab82173431241d6323b47b4576 to your computer and use it in GitHub Desktop.
Cell nib template file, because every time I need it I open my old projects.
//
// CellNib.swift
// miitiOS
//
// Created by Luis Fernando Mata on 8/31/19.
// Copyright © 2019 Miit. All rights reserved.
//
import UIKit
public struct CellNib {
public enum CollectionView: String {
case myCell
var NibClass: AnyClass? {
switch self {
default:
return nil
}
}
}
public enum TableView: String {
case myCell
var NibClass: AnyClass? {
switch self {
default:
return nil
}
}
}
public enum ReusableView: String {
case myReusableView
}
}
extension UICollectionView {
public func register(nib: CellNib.CollectionView) {
// Check if class has a declared Class or should use a xib file
if let nibClass = nib.NibClass {
self.register(nibClass, forCellWithReuseIdentifier: nib.rawValue)
return
}
self.register(UINib(nibName: nib.rawValue, bundle: nil), forCellWithReuseIdentifier: nib.rawValue)
}
public func registerReusable(_ nib: CellNib.ReusableView, kind: String) {
self.register(UINib(nibName: nib.rawValue, bundle: nil), forSupplementaryViewOfKind: kind, withReuseIdentifier: nib.rawValue)
}
}
extension UITableView {
public func register(nib: CellNib.TableView) {
// Check if class has a declared Class or should use a xib file
if let nibClass = nib.NibClass {
self.register(nibClass, forCellReuseIdentifier: nib.rawValue)
return
}
self.register(UINib(nibName: nib.rawValue, bundle: nil), forCellReuseIdentifier: nib.rawValue)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment