Last active
April 22, 2018 10:19
-
-
Save jkereako/648173edc94fea4055047bd990508a57 to your computer and use it in GitHub Desktop.
Common extensions for UIViewController.
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
// | |
// 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) | |
} | |
} | |
} |
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
// | |
// 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