Deinitialization

Deinitialization states that, A deinitializer denit will be called immediately before a class instance is deallocated.
It’s the counter part of Initialization.

Constraints:
Applicable to class type.

Deinitialization in Action.
We have taken two class named as Foo(Parent) and Bar(Child) each having `init` and `deinit`

When we create instance of `Bar` the order of execution takes in this manner

Parent Class init -> Child Class init
Child Class deinit -> Parent Class deinit

Question: Provided we have parent-child relationship, What’s the order in which deinit is called?

class Parent {
deinit { print(“Parent deinit”) }
}

class Child: Parent {
deinit { print(“Child deinit”) }
}

Further reading:
https://docs.swift.org/swift-book/LanguageGuide/Deinitialization.html

Thanks for reading.
Please let me know if you have any queries or doubt.

roshankumar350@gmail.com
Roshan kumar Sah.

--

--