Is it just me or Xcode isn’t the piece of software it used to be ? I mean, it’s never been awesome but recently I crash it 2-3 times a day. Not to mention the two fingers swipe ( for back & fwd ) that also breaks often. I expect the same software quality from Apple that my clients expect from me.
Sorry its been a while here it is :
The Extension of the month
Simple but handy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import Foundation typealias ViewControllerStoryboardInfo = (name: String, id: String?) protocol Container { } extension Container where Self: UIViewController { func addChildViewController(withInfo info: ViewControllerStoryboardInfo)-> UIViewController? { var viewController: UIViewController! = nil switch info.id { case let identifier where identifier != nil: viewController = UIStoryboard(name: info.name, bundle: nil).instantiateViewController(withIdentifier: identifier!) default: viewController = UIStoryboard(name: info.name, bundle: nil).instantiateInitialViewController() } if let viewController = viewController { self.addChildViewController(viewController) viewController.view.frame = self.view.bounds self.view.addSubview(viewController.view) viewController.didMove(toParentViewController: self) return viewController } return nil } func removeAllChildViewController() { self.childViewControllers.forEach({ (controller) in controller.view.removeFromSuperview() controller.willMove(toParentViewController: nil) controller.removeFromParentViewController() }) } } |
Well thank you 🙂 Very much appreciated !
Thank you very much 🙂