ODENZA

The reason to use xcodegen is solve merge conflicts on .xcodeproj file

XcodeGen is a command line tool written in Swift that generates your Xcode project using your folder structure and a project spec.

Easy way to install xcodegen package on Mac using HomeBrew

  1. Install HomeBrew
    If your mac do not install HomeBrew, Install it first.
    Open Terminal and run code as below.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

2. Install xcodegen using Brew by command below.

brew install xcodegen

Finish! Now, xcodegen is ready to use!

--

--

In this article, I would like to show you how to create extension for add your childView.

protocol Containable {
func add(childView: UIViewController, container: UIView)
func remove(childView: UIViewController)
}
extension Containable where Self: UIViewController {
func add(
childView: UIViewController,
container: UIView) {
addChild(childView)
container.addSubview(childView.view)
childView.view.frame = container.bounds
childView.didMove(toParent: self)
}
func remove(childView: UIViewController) { childView.willMove(toParent: nil)
childView.view.removeFromSuperview()
childView.removeFromParent()
}
}

How to use it.

class ViewController: UIViewController, Containable {   @IBOutlet weak var yourView: UIView!
let yourViewController = YourViewController(nibName: "YourViewController", bundle: nil)
override func viewDidLoad() {
super.viewDidLoad()
add(childView: yourViewController, container: yourView)
}
}

--

--