I have created a UINavigationController
object and set it as the window's rootViewController
property.
The rootViewController
of the UINavigationController
object is a class called UINavigationMenuViewController
.
If I want to navigate from UINavigationMenuViewController
to UIUserProfileViewController
for example, I can use:
navigationController!.pushViewController(userProfileVC, animated: true)
as well as
navigationController?.pushViewController(userProfileVC, animated: true)
The effect seems to be the same. I am wondering what's the difference.
I would guess the second way is more secure, and in case I forget to embed the UINavigationMenuViewController
object inside the UINavigationController
, the app would not crash, comparing to the first case. I guess it's also called optionals chaining, I am just not quite sure as I am still learning Swift.
Please give me some advice.