The death of View Lifecycle
Hello people, Leo here.
Today I want to explain what was the old view lifecycle and why it's already obsolete. First of all the what I'm calling "old view life cycle" is technically the UIViewController life cycle. It has some method that we can override to enable our screen to behave the way and when we wanted. The methods are listed below :
It's not the scope of this article explain each one of those but it's important to know how and why override them in your code. For example: Early on my development learning I thought that viewDidLoad was called every time a view is called... I couldn't be more wrong. The viewDidLoad is called just ONE time for each view, when... guess what... the view was loaded. The method I should override was viewWillAppear to achieve the behavior that I wanted. So this kind basic understanding is essential to any developer until now because now we have the almighty swiftUI and all this lifecycle methods where gone for good. ( at least in pure swiftUI code base)
In swiftUI you will not have a lifecycle, you will have only the events occurring throughout your app. You have a large Tool box of states and data flows that you can use all around your app. And yes, if you are thinking environment is just a big singleton, you are right and we no one died because of that, just get over it. And you also have the :
onAppear - onDisappear
For onAppear and onDisappear, they are available as properties on View and mock the appear-like events in the old lifecycle, this is very useful when we are thinking on migrating behaviors from old apps to swiftUI apps.
That's the resume of it, the future is bright and we no more need to care about all the view lifecycle because swiftUI deal with states and data flows.
Thanks for the reading and... That's all folks!