我正在使用以下代码添加观察者:
[self.priorityQueue addObserver:self forKeyPath:@"operations" options:options context:NULL];
并且观察方法定义为:
-(void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context
{
if ([object isKindOfClass:[NSOperationQueue class]] && [keyPath isEqualToString:@"operations"]) {
//calling my method
}
else {
[super observeValueForKeyPath:keyPath ofObject:object
change:change context:context];
}
}
但我收到以下错误:
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“(上下文:0x0,属性:0x110bf60>):已收到 -observeValueForKeyPath:ofObject:change:context: 消息但未处理。关键路径:操作观察对象:{name = 'NSOperationQueue 0x11213c0'} 更改:
请告诉我,如果我在观察者方法中犯了一些错误。
谢谢,