Skip to content

Instantly share code, notes, and snippets.

@VAndrJ
Last active January 3, 2025 08:40
Show Gist options
  • Save VAndrJ/c0e84c083e49357bb9e6a88987998351 to your computer and use it in GitHub Desktop.
Save VAndrJ/c0e84c083e49357bb9e6a88987998351 to your computer and use it in GitHub Desktop.
UINavigationController pushViewController iOS 18.0+ optimization(issue?) example.
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(
_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
) {
guard let scene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: scene)
let navController = UINavigationController(
rootViewController: RootViewController()
)
window?.rootViewController = navController
window?.makeKeyAndVisible()
navController.pushViewController(
PushedViewController(),
animated: true
)
}
}
class RootViewController: BaseViewController {}
class PushedViewController: BaseViewController {}
class BaseViewController: UIViewController {
override func loadView() {
super.loadView()
print("\(Self.self)", #function)
}
override func viewDidLoad() {
super.viewDidLoad()
print("\(Self.self)", #function)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
print("\(Self.self)", #function)
}
override func viewIsAppearing(_ animated: Bool) {
super.viewIsAppearing(animated)
print("\(Self.self)", #function)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
print("\(Self.self)", #function)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
print("\(Self.self)", #function)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
print("\(Self.self)", #function)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment