Search code examples
swiftkey-value-observing

Observing Multiple NSKeyObservingKeyValueoptions swift


How to observe multiple NSKeyObservingKeyValueoptions in swift

 self.avplayerItem.addObserver(self, forKeyPath: "status", options:[.Initial | .New], context: nil)

I get an error like

Error

No '|' candidates produce the expected contextual result type 'NSKeyValueObservingOptions'


Solution

  • Change

     self.avplayerItem.addObserver(self, forKeyPath: "status", options:[.Initial | .New], context: nil)
    

    to:

     self.avplayerItem.addObserver(self, forKeyPath: "status", options:[.Initial, .New], context: nil)