KVO does not work with keypath like com.alpha.

My NSMutableDictionary contains simple keys (@ "one", @ "two", @ "three") and complex keys (@ "com.alpha", @ "com.beta"). Can observers be used for a complex key?

Observers work well with simple keys, but do not work with complex keys. What is the solution?

[self.dict addObserver:self forKeyPath:@"com.alpha" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil];

-(IBAction) onChange:(id)sender
{
 [self.dict setObject:@"newValue" forKey:@"com.alpha"];
}

-(void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
  NSLog(@"____ value had changed");
}
0
source share
2 answers

, . - . , . (. " " " ".)

,

id x = [object valueForKeyPath:@"com.alpha"];

id x = [[object valueForKey:@"com"] valueForKey:@"alpha"];

"com.alpha" , . "Com_alpha".

+4

NSDictionary . KVO. , .

0

Source: https://habr.com/ru/post/1682351/


All Articles