Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do this very easily by just implementing the observer to compare. Following is just an example to implement the custom observer to compare</p> <pre><code>@implementation NSArray (KVO) - (void)addObserver:(NSObject *)observer toObjectsAtIndexes:(NSIndexSet *)indexes forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context { NSUInteger idx=[indexes firstIndex]; while(idx!=NSNotFound) { [[self objectAtIndex:idx] addObserver:observer forKeyPath:keyPath options:options context:context]; idx=[indexes indexGreaterThanIndex:idx]; } } - (void)removeObserver:(NSObject *)observer fromObjectsAtIndexes:(NSIndexSet *)indexes forKeyPath:(NSString *)keyPath { NSUInteger idx=[indexes firstIndex]; while(idx!=NSNotFound) { [[self objectAtIndex:idx] removeObserver:observer forKeyPath:keyPath]; idx=[indexes indexGreaterThanIndex:idx]; } } -(void)addObserver:(id)observer forKeyPath:(NSString*)keyPath options:(NSKeyValueObservingOptions)options context:(void*)context; { if([isa instanceMethodForSelector:_cmd]==[NSArray instanceMethodForSelector:_cmd]) NSRaiseException(NSInvalidArgumentException,self,_cmd,@"not supported for key path %@ (observer was %@)", keyPath, observer); else [super addObserver:observer forKeyPath:keyPath options:options context:context]; } -(void)removeObserver:(id)observer forKeyPath:(NSString*)keyPath; { if([isa instanceMethodForSelector:_cmd]==[NSArray instanceMethodForSelector:_cmd]) NSRaiseException(NSInvalidArgumentException,self,_cmd,@"not supported for key path %@ (observer was %@)", keyPath, observer); else [super removeObserver:observer forKeyPath:keyPath]; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload