When should I use deinit?

后端 未结 6 1441
谎友^
谎友^ 2020-12-08 06:55

I came across a function called deinit() while reading The Swift Programming Language guide, but I\'m still wondering why and when we need to implement it since

6条回答
  •  忘掉有多难
    2020-12-08 07:09

    A deinitilizer is called immediately before a class instance is deallocated ,and it is helpful when you are working with your own resources .For Example If you creat a custom class to open a file and write some data to it ,you might need close the file before the class instance is deallocated .Most important is Class definition can have at most one deintilizer per class

提交回复
热议问题