Objective-C: Where to remove observer for NSNotification?

前端 未结 14 1629
北海茫月
北海茫月 2020-11-29 19:37

I have an objective C class. In it, I created a init method and set up a NSNotification in it

//Set up NSNotification
[[NSNotificationCenter defaultCenter] a         


        
14条回答
  •  情深已故
    2020-11-29 19:52

    In swift use deinit because dealloc is unavailable:

    deinit {
        ...
    }
    

    Swift documentation:

    A deinitializer is called immediately before a class instance is deallocated. You write deinitializers with the deinit keyword, similar to how intializers are written with the init keyword. Deinitializers are only available on class types.

    Typically you don’t need to perform manual clean-up when your instances are deallocated. However, when you are working with your own resources, you might need to perform some additional clean-up 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.

提交回复
热议问题