When should I use deinit?

后端 未结 6 1415
谎友^
谎友^ 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:31

    If your class manages a file handle or a different resource you can close that handle in deinit to ensure that it doesn't live on after the object has been freed.

提交回复
热议问题