Skip to content

Instantly share code, notes, and snippets.

@shanecowherd
Created November 12, 2019 23:06
Show Gist options
  • Save shanecowherd/d279c623d922429d1c7ef7c892f56a33 to your computer and use it in GitHub Desktop.
Save shanecowherd/d279c623d922429d1c7ef7c892f56a33 to your computer and use it in GitHub Desktop.
Example Operation
let operationQueue = OperationQueue()
class ExampleOperation: Operation {
var delegate: SomeDelegate
var callbackDelegate: SomeCallbackDelegate
var success = false // I mark this when the operation has succeeded. Optional
init(delegate: SomeDelegate, callbackDelegate: SomeCallbackDelegate) {
self.delegate = delegate
self.callbackDelegate = callbackDelegate
}
override func main() {
let waitForFinish = DispatchGroup()
waitForFinish.enter()
// Do stuff here and leave when you are done
waitForFinish.leave()
waitForFinish.wait()
if self.isCancelled { return }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment