Skip to content

Instantly share code, notes, and snippets.

@jkereako
Last active April 22, 2018 10:19
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 jkereako/648173edc94fea4055047bd990508a57 to your computer and use it in GitHub Desktop.
Save jkereako/648173edc94fea4055047bd990508a57 to your computer and use it in GitHub Desktop.
Common extensions for UIViewController.
//
// UITableViewExtensions.swift
//
// Created by Jeff Kereakoglow on 4/22/18.
// Copyright © 2018 AlexisDigital. All rights reserved.
//
import UIKit.UITableView
extension UITableView {
func registerNibsWithReuseIdentifierMap(_ reuseIdentifierMap: [String: UITableViewCell.Type]) {
reuseIdentifierMap.forEach { (reuseIdentifier, cellType) in
let nib = UINib(nibName: reuseIdentifier, bundle: Bundle(for: cellType))
self.register(nib, forCellReuseIdentifier: reuseIdentifier)
}
}
}
//
// UIViewControllerExtensions.swift
//
// Created by Jeff Kereakoglow on 9/4/17.
// Copyright © 2017 Alexis Digital. All rights reserved.
//
import UIKit.UIViewController
extension UIViewController {
func addChildViewController(_ childViewController: UIViewController, toView view: UIView) {
childViewController.willMove(toParentViewController: self)
addChildViewController(childViewController)
childViewController.view.frame = view.bounds
view.addSubview(childViewController.view)
childViewController.didMove(toParentViewController: self)
}
func removeChildViewController(_ childViewController: UIViewController) {
childViewController.removeFromParentViewController()
childViewController.view.removeFromSuperview()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment