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

前端 未结 10 1502
萌比男神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条回答
  •  旧巷少年郎
    2020-12-04 07:29

    [someObject observationInfo] return nil if there is no observer.

    if ([tableMessage observationInfo] == nil)
    {
       NSLog(@"add your observer");
    }
    else
    {
      NSLog(@"remove your observer");
    
    }
    

提交回复
热议问题