cocoa - KVO's add & remove observer methods – counted or idempotent? -
in kvo subscribe receive change notifications potential sender with:
[potentialsender addobserver: self forkeypath: nsstringfromselector(@selector(aproperty)) options: 0 context: mykvohandle]; and can unsubscribe with:
[potentialsender removeobserver: self forkeypath: nsstringfromselector(@selector(aproperty)) context: mykvohandle]; where kvo handles might created this c idiom.
are calls these counted – every add must directly paired , precede remove – pre-arc retain , release?
alternatively, idempotent – number of add calls can stopped single remove, several remove operations without matching add safe?
i believe idempotent approach used [acontrol addtarget:action:forcontrolevents:] and . wrong notification centre [anotificationcentre addobserver:selector:name:object:]addobserver calls. not idempotent. however, removes are. rob correcting me on this.
kvo calls must balanced. every addobserver:... must balanced equivalent removeobserver:.... , there no mechanism "unsubscribe all" there nsnotificationcenter. remove not balance add error. kvo picky.
note nsnotificationcenter absolutely not idempotent. multiple, identical addobserver:... calls result in multiple notifications. it's possible global removeobserver:self without balancing every addobserver:..., , safe remove when have not added.