2

First of all I would like to say that I'm not that advanced in swift. But I wanted to build a custom videoplayer on top of the player library which can be found here:

https://github.com/piemonte/Player

While including it in my swift 3.0 project I ran into some problems that I can't solve myself so I would like to ask you guys for a bit of help. I'm receiving the following error:

Expression pattern of type 'Int' cannot match values of type UnsafeMutablePointer<Void>?

This happens in the following bit of code. (I excluded all irrelevant pieces, so the code might jump from time to time.):

private var PlayerObserverContext = 0

private func commonInit() {
   self.player.addObserver(self, forKeyPath: PlayerRateKey, options: ([NSKeyValueObservingOptions.new, NSKeyValueObservingOptions.old]) , context: &PlayerObserverContext)
}

deinit {
    self.player.removeObserver(self, forKeyPath: PlayerRateKey, context: &PlayerObserverContext)
}

override public func observeValue(forKeyPath keyPath: String?, of object: AnyObject?, change: [NSKeyValueChangeKey : AnyObject]?, context: UnsafeMutablePointer<Void>?) {
switch (keyPath, context) {
    case (.some(PlayerRateKey), PlayerObserverContext):
        true
    default:
        true
}

The error takes place on the line: case (.some(PlayerRateKey), PlayerObserverContext):

I hope this is enough. If you have any questions or want me to clarify some things a bit more let me know! Thanks in advance.

  • 1
    You should use `&PlayerObserverContext` like you did above. – jtbandes Jul 25 '16 at 21:40
  • Tried that, but that's giving me another problem and Xcode tells me to delete the & sign. It says: ```'&' used with non-inout argument of type '_OptionalNilComparisonType'``` Not so sure what to do with that :( –  Jul 25 '16 at 21:42
  • Maybe try it without using `switch`. – jtbandes Jul 25 '16 at 21:43
  • Could you point me in the right direction on how to do that? Doesn't need to be complete code or fully functional code, just a small example in the right direction. –  Jul 25 '16 at 21:49
  • 2
    http://stackoverflow.com/questions/24175626/adding-observer-for-kvo-without-pointers-using-swift/32701309#32701309 – jtbandes Jul 25 '16 at 21:51
  • Cool! Let me try that, will let you know if it worked! :) –  Jul 25 '16 at 21:59
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/118266/discussion-between-wouter125-and-jtbandes). –  Jul 25 '16 at 22:02
  • Nevermind. Already got it working. The author of library had it already updated to Swift 3.0. :) –  Jul 26 '16 at 06:47

0 Answers0