Skip to content

Instantly share code, notes, and snippets.

@showcove
Last active November 6, 2021 06:04
Show Gist options
  • Save showcove/f63e88423832236a2dd0a084ee9a0b91 to your computer and use it in GitHub Desktop.
Save showcove/f63e88423832236a2dd0a084ee9a0b91 to your computer and use it in GitHub Desktop.
PushVsModal-1
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func pushViewController() {
let targetViewController = UIViewController.viewControllerFromMainStoryboard(identifier: ViewController.storyboardIdentifier)
self.navigationController?.pushViewController(targetViewController, animated: true)
}
}
extension UIViewController {
static var storyboardIdentifier: String {
return String(describing: self)
}
static func viewControllerFromMainStoryboard(identifier: String) -> UIViewController {
return viewController(storyboardName: "Main", identifiler: identifier)
}
static func viewController(storyboardName: String, identifiler: String) -> UIViewController {
let storyboard = UIStoryboard(name: storyboardName, bundle: nil)
if #available(iOS 13.0, *) {
return storyboard.instantiateViewController(identifier: identifiler)
} else {
return storyboard.instantiateViewController(withIdentifier: identifiler)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment