問題タブ [addobserver]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
ios - iOS NotificationCenter の予期しない保持閉鎖
ドキュメントでは、次のように述べています。
ブロックは通知センターによってコピーされ、(コピーは) オブザーバー登録が削除されるまで保持されます。
そして、次のような 1 回限りのオブザーバーのサンプル コードを提供します。
呼び出されたときにオブザーバーが削除されることを期待しているremoveObserver(_:)
ので、コードは次のようになります。
驚くべきことに、self
は保持され、削除されません。
何が起こっている?