-1

I subscribed one object for some changes from another object like this:

[objA addObserver:self
       forKeyPath:keyPath
          options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
      context:nil];

And when changes are made the

- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context

is called.

But values for "new" and "old" keys for change dictionary are always the same. This issue is reproducible only in iOS 4.x. In iOS 5.x it works fine. Any suggestions?

Dave FN
  • 652
  • 1
  • 14
  • 29
leon4ic
  • 339
  • 4
  • 12

1 Answers1

0

It depends upon what you're observing and how that object has changed. Notably, if the object pointer is not changing, but rather some property/attribute of that object has changed (e.g. you have a NSMutableArray and you just add a value to the array, but the address of the NSMutableArray itself hasn't changed), the new and old pointers are actually pointing to the same object, so it will look unchanged. Frequently in these cases, you won't even get the notification of the change, but even if you manually invoke the willChangeValueForKey and didChangeValueForKey in, for example, some custom setter, the old value will look the same as the new value. If you change your code that is changing the value to actually creating a new copy of the object and releasing the old one, then you'll see your new and old values changing.

Make sure to your object is KVO Compliant, too.

If you want more help, you'll have to provide more specifics (notably, the source code) about the object that you're changing and how you're changing it.

Rob
  • 415,655
  • 72
  • 787
  • 1,044