Skip to content

Instantly share code, notes, and snippets.

@jasdev
Created February 15, 2016 03:04
Show Gist options
  • Save jasdev/ba9f03747086d4939e55 to your computer and use it in GitHub Desktop.
Save jasdev/ba9f03747086d4939e55 to your computer and use it in GitHub Desktop.
NSOperation Subclass with KVO Notifications
class Operation: NSOperation {
override var asynchronous: Bool {
return true
}
private var _executing = false {
willSet {
willChangeValueForKey("isExecuting")
}
didSet {
didChangeValueForKey("isExecuting")
}
}
override var executing: Bool {
return _executing
}
private var _finished = false {
willSet {
willChangeValueForKey("isFinished")
}
didSet {
didChangeValueForKey("isFinished")
}
}
override var finished: Bool {
return _finished
}
override func start() {
_executing = true
execute()
}
func execute() {
fatalError("You must override this")
}
func finish() {
_executing = false
_finished = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment