objective c - CFNotificationCenterRemoveObserver observer -


in reference see registering observer notifications possible null observer pointer. however, both remove methods require valid pointer value not null. how overcome when registration done without one?

i noticed in answer example cfnotificationcenter usage examples? removing done null, again, according reference - wrong .

so, right way remove registration done null observer? not supposed removed (they left there till memory cleared due application exit??)???

any explanation appreciated!

there's no real penalty sending observer (which void *, , not interpreted system @ all). preferred use case if going remove observer, should send observer both initial cfnotificationcenteraddobserver call , subsequent cfnotificationcenterremoveobserver.

by example, appears passing null both add , remove works, point out breaks api contract so, therefore wouldn't suggest using in shipping code.

the observer string pointer , long pass in same pointer, should fine.

char *myobserver="anobserver";  cfnotificationcenteraddobserver ( notificationcenter, (void*)myobserver, mycallback, null, null, cfnotificationsuspensionbehaviordrop); 

and later:

cfnotificationcenterremoveobserver ( notificationcenter, (void*)myobserver, null, null);   

make sure use same string pointer, not same string, foundation checking equality of void*, knows nothing contents.

by way of further explanation, reason pattern can use single callback handle multiple observers.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -