1

I’m trying to observe when a new dependency is being added to an operation:

let token = operation.observe(\.dependencies, options: [.old, .new]) { (operation, changes) in
  print("dependencies modified")
}

operation.addDependency(operation2)

But the callback is never fired, is this the correct way?

Alessandro
  • 686
  • 12
  • 19
  • Does this answer your question? [Swift 4 approach for observeValue(forKeyPath:...)](https://stackoverflow.com/questions/47562977/swift-4-approach-for-observevalueforkeypath) – Willeke Feb 17 '20 at 17:08
  • No, I'm already using the Swift KVO approach. The "dependencies" property is the only KVO-compliant property whose changes I'm not able to observe – Alessandro Feb 18 '20 at 08:21
  • The ownership section "You're the owner of the NSKeyValueObservation instance the observe function returns, meaning, you don't have to addObserver nor removeObserver anymore; rather, **you keep a strong reference to it for as long as you need your observation observing**." of the answer doesn't help? – Willeke Feb 18 '20 at 08:24
  • No, I've created a gist to illustrate the problem: https://gist.github.com/alemar11/3568ad1c1a93c742e94184d361440526 – Alessandro Feb 18 '20 at 08:51
  • Looks like a bug to me. What happens if you also observe `isReady`. – Willeke Feb 18 '20 at 12:02
  • isReady gets observed without any problems, it seems that dependencies is no more KVO compliant (I will open a feedback). Thanks – Alessandro Feb 18 '20 at 13:30

0 Answers0