Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.