There is a common misunderstanding with KVO: It is not possible to observe the inner state of an otherwise KVO compliant property.
That's the case with the NSData: From the KVO point of view the data property of your object does not change, it's its state of the NSData that changes. If NSMutableData would expose KVO compliant properties for its contents you could observe changes by observing a key path (like @"data.contents") but that's not the case.
KVO only works for KVC compliant properties that are also documented to be KVO compliant. Most Cocoa framework classes don't give that guarantee and it's a bug to observe the objects and their key paths.
A solution for your case would be not to expose an NSMutableData
as a public property but instead use an immutable data and add methods like appendData:
to your custom class. That would give you the opportunity to do the changes to the data object in these methods and emit KVO notifications manually (using willChangeValueForKey:@"data"
... do the change ... didChangeValueForKey:@"data"
).