Skip to content

Instantly share code, notes, and snippets.

@toshi0383
Created June 13, 2017 01:47
Show Gist options
  • Save toshi0383/8c05f6ef5f5cc57d5d0216ec018b85bf to your computer and use it in GitHub Desktop.
Save toshi0383/8c05f6ef5f5cc57d5d0216ec018b85bf to your computer and use it in GitHub Desktop.
なんぞこれ #CodePiece
var player: AVPlayer?
func testDeallocatePlayerCrashes() {
player = MyPlayer()
// NSUnknownKeyException "...was sent to an object that is not KVC-compliant for the "bbbbbbb" property"
// player?.addObserver(self, forKeyPath: "bbbbbbb.aaaaaaaaa", options: [.new], context: nil)
// NSInternalInconsistencyException "...was deallocated while key value observers were still registered with it."
// player?.addObserver(self, forKeyPath: "", options: [.new], context: nil)
// No crash
player?.addObserver(self, forKeyPath: "rate", options: [.new], context: nil)
player = nil // MyPlayer.deinit() is called.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment