Search code examples
ioskey-value-observingkvocontroller

Why will app crash if did not remove KVO observer before dealloc?


I understand we need to remove KVO observe before instance dealloc.

But Why would this crash happen?


Solution

  • If you use the Swift4 KVO, then you don't need to. It's safely handled.

    That being said it was needed before, because sending messages to deallocated instances crashes the app. The concept is similar to the answer mentioned here.

    To read more about the memory management of the Swift3 vs Swift4 KVO see here