Your First Swift 4 & iOS 11 App - Part 35: | Ray Wenderlich

Practice adding multiple screens into your iOS apps, by adding an About the Author screen into Bull's Eye.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3990-your-first-swift-4-ios-11-app/lessons/35

Couldn’t you just create a Present Modally segue from AboutViewController to the original view controller instead of using dismiss? Is that a code smell or something?

When you dismiss a view controller, the view controller is removed from the navigation stack and memory, and all of its resources are released.

If you don’t dismiss but instead have a segue back to the parent view controller, then you create a loop where you have the original view controller showing the About view controller and then the About view controller showing a new copy of the parent view controller. In this scenario, instead of releasing memory, you are actually using up more memory since you now have two copies of the parent view controller active. This is not a good way to go :slight_smile:

Also, the navigation stack now would look like this:

Parent - About - Parent

And if you show the about view controller again from the parent view controller, then the navigation stack would look like:

Parent - About - Parent - About

So you just keep adding more view controllers to the navigation stack each time you move back and forth between the About view controller and its parent if you do not dismiss the About view controller.

Hope this makes sense?

1 Like

Thank you for a really well explained response! The navigation stack bit was a good foil to what I know about stack frames during function calls.

This topic was automatically closed after 166 days. New replies are no longer allowed.