Aran Mulholland Aran Mulholland - 1 year ago 99
Objective-C Question

How can i tell if an object has a key value observer attached

if you tell an objective c object to removeObservers: for a key path and that key path has not been registered, it cracks the sads. like -

'Cannot remove an observer for the key path "theKeyPath" from because it is not registered as an observer.'

is there a way to determine if an object has a registered observer, so i can do this

if (object has observer){
remove observer
go on my merry way

Answer Source

Put a try catch around your removeObserver call

   [someObject removeObserver:someObserver forKeyPath:somePath];
}@catch(id anException){
   //do nothing, obviously it wasn't attached because an exception was thrown
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download