Member-only story
SwiftUI View Lifecycle as UIViewController
As you know that while you develop an ios app. Then you can use both UI frameworks UIKit & SwiftUI in the app. But sometimes, you can have a situation where you want to use same UIViewController life cycle events in the SwiftUIView.
Get Started
Let suppose you have 2 screens in the app. First screen is developed by UIKit framework but second screen is developed by SwiftUI framework. Now you want to use ‘viewWillAppear’ & ‘viewDidAppear’ life cycle events. Both are the part of UIViewController life cycle event but not present in the SwiftUIView.
Now, you can have both the life cycle events by the help of some extended modifiers.
Here is the extension code:
How to use:
As all of these are the closure functions of View so you can access them directly. See below code screenshot:
Thank You! Happy coding! 👍