The right place to call .removeObserver for NSNotificationCenter = Swift deinit()?

前端 未结 2 887
梦如初夏
梦如初夏 2021-01-17 18:52

I\'ve read a lot of suggestions for the right place to call .removeObserver for NSNotificationCenter since viewDidUnload is not an option.

I was just wondering if t

2条回答
  •  半阙折子戏
    2021-01-17 19:29

    If you were previously calling removeObserver in viewDidUnload/dealloc/deinit, then starting with iOS 9.0 and macOS 10.11, you don't need to call it anymore:

    If your app targets iOS 9.0 and later or macOS 10.11 and later, you don't need to unregister an observer in its dealloc method.

    source: https://developer.apple.com/documentation/foundation/notificationcenter/1413994-removeobserver

提交回复
热议问题