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

前端 未结 10 1499
萌比男神i
萌比男神i 2020-12-04 06:51

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 observe

10条回答
  •  Happy的楠姐
    2020-12-04 07:05

    Put a try catch around your removeObserver call

    @try{
       [someObject removeObserver:someObserver forKeyPath:somePath];
    }@catch(id anException){
       //do nothing, obviously it wasn't attached because an exception was thrown
    }
    

提交回复
热议问题