Skip to content

Instantly share code, notes, and snippets.

@olbrichj
Created January 29, 2018 21:29
Show Gist options
  • Save olbrichj/294aca0f8025876d77d9f7505321befa to your computer and use it in GitHub Desktop.
Save olbrichj/294aca0f8025876d77d9f7505321befa to your computer and use it in GitHub Desktop.
import Foundation
class OperationObserver: NSObject {
init(operation: AsyncOperation) {
super.init()
operation.addObserver(self, forKeyPath: "finished", options: .new, context: nil)
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
guard let key = keyPath else {
return
}
switch key {
case "finished":
print("done")
default:
print("doing")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment