Skip to content

Commit

Permalink
feat: add helpers to add child view controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
gtokman committed May 3, 2021
1 parent 3075954 commit 3159b7c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Sources/ExtensionKit/UIKit/UIViewController.swift
Expand Up @@ -9,6 +9,24 @@ public extension UIViewController {

/// ViewController class name
var classNameValue: String { NSStringFromClass(self.classForCoder).components(separatedBy: ".").last! }

/// Adds a child viewController to the current controller view
/// - Parameter viewController: The child view
func addChild(viewController: UIViewController, in view: UIView) {
addChild(viewController)
view.addSubview(viewController.view)
viewController.view.frame = view.bounds
viewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
viewController.didMove(toParent: self)
}

/// Removes a child viewController from current
/// - Parameter viewController: The child view controller to remove
func removeChild(viewController: UIViewController) {
viewController.willMove(toParent: nil)
viewController.view.removeFromSuperview()
viewController.removeFromParent()
}

/// Combine an array of models and an array of views.
///
Expand Down

0 comments on commit 3159b7c

Please sign in to comment.