Skip to content

Instantly share code, notes, and snippets.

@fmo91
Created March 27, 2018 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fmo91/7e25d1266b79a20ec492be5c01e708f7 to your computer and use it in GitHub Desktop.
Save fmo91/7e25d1266b79a20ec492be5c01e708f7 to your computer and use it in GitHub Desktop.
Base Operation class for Operation/OperationQueue concurrency pattern in iOS.
// From here https://agostini.tech/2017/07/30/understanding-operation-and-operationqueue-in-swift/
class BaseOperation: Operation {
private var _executing = false {
willSet {
willChangeValue(forKey: "isExecuting")
}
didSet {
didChangeValue(forKey: "isExecuting")
}
}
override var isExecuting: Bool {
return _executing
}
private var _finished = false {
willSet {
willChangeValue(forKey: "isFinished")
}
didSet {
didChangeValue(forKey: "isFinished")
}
}
override var isFinished: Bool {
return _finished
}
func executing(_ executing: Bool) {
_executing = executing
}
func finish(_ finished: Bool) {
_finished = finished
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment