Last active
August 31, 2019 04:32
-
-
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.
This file contains 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
// | |
// 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