I have actually solved the problem. I have found that Xcode did not detect the navigation controller and as I have used optional chaining, the code did not get executed.
I have fixed the problem, by simply deleting and adding the Navigation Controller again.
Thanks for the help