bindingnsoperationnsrangeexception

Cannot remove an observer <NSArrayController> for the key path "count"


I am getting:

*** Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <NSArrayController> for the key path "count" from <MyElement> because it is not registered as an observer.'

I have a background NSOperation which is populating the properties of MyElement. These MyElement objects are in an array managed by NSArrayController and are bound to a NSTableView.

Could this be related to changing properties on a background thread and if so, how can I disable that so that the table doesn't see those changes until they are complete (and can be updated on the main thread)?

I have it set to sort by a "size" (NSNumber) property and

The crash looks like:

0 CoreFoundation   0x00007fff87ec44f2 __exceptionPreprocess + 178
1 libobjc.A.dylib  0x00007fff85d6cf7e objc_exception_throw + 48
2 CoreFoundation   0x00007fff87f2b4bd +[NSException raise:format:] + 205
3 Foundation       0x00007fff8755d786 -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] + 504
4 Foundation       0x00007fff8755d533 -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] + 108
5 Foundation       0x00007fff875ce1a4 -[NSObject(NSKeyValueObserverRegistration) 
...
15  Foundation     0x00007fff87572a69 _NSSetObjectValueAndNotify + 274
16  MyApp          0x0000000100051a10 -[MyPropertiesOperation main] + 496

Solution

  • It seems that I can't modify these objects in a background thread, and I see no way to temporarily suspend an observer, so instead I am adding all the properties to a dictionary on the background thread and then on the main thread calling:

    [element setValuesForKeysWithDictionary:properties];