Skip to content

Instantly share code, notes, and snippets.

@SlaunchaMan
Created June 7, 2017 15:44
Show Gist options
  • Save SlaunchaMan/9e7a6317f9c862e3912bcd0c96704f65 to your computer and use it in GitHub Desktop.
Save SlaunchaMan/9e7a6317f9c862e3912bcd0c96704f65 to your computer and use it in GitHub Desktop.
Attempting to use the new block-based KVO in Xcode 9 and Swift 4
//: Playground - noun: a place where people can play
import Foundation
class HelloThere: NSObject {
@objc var value: String = ""
}
let object = HelloThere()
let observer = object.observe(\.value) { (object, change) in
print("Changed to \(object.value)")
}
object.value = "1"
object.value = "2"
object.value = "3"
print("At end")
@SlaunchaMan
Copy link
Author

This just prints "At end"—none of the KVO notifications actually fire.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment