deinit keyword defines deinitializer, that will be called immediately before a class instance is deallocated.

Typically you don’t need to perform manual cleanup when your instances are deallocated. However, when you are working with your own resources, you might need to perform some additional cleanup yourself. For example, if you create a custom class to open a file and write some data to it, you might need to close the file before the class instance is deallocated.

Only class types can define deinitializer.

class MyCls{
    // ...
    deinit {
        // ... cleanup code