Last active
November 6, 2021 06:04
-
-
Save showcove/f63e88423832236a2dd0a084ee9a0b91 to your computer and use it in GitHub Desktop.
PushVsModal-1
This file contains hidden or 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
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