Created
February 15, 2016 03:04
-
-
Save jasdev/ba9f03747086d4939e55 to your computer and use it in GitHub Desktop.
NSOperation Subclass with KVO Notifications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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