Created
March 27, 2018 00:37
-
-
Save fmo91/7e25d1266b79a20ec492be5c01e708f7 to your computer and use it in GitHub Desktop.
Base Operation class for Operation/OperationQueue concurrency pattern in iOS.
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
// 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