Skip to content

Instantly share code, notes, and snippets.

@stevencurtis
Created June 10, 2020 10: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 stevencurtis/5f5f07f25a0b4d62096bd9f927007fc8 to your computer and use it in GitHub Desktop.
Save stevencurtis/5f5f07f25a0b4d62096bd9f927007fc8 to your computer and use it in GitHub Desktop.
OperationHelloWorld
class PrintOperation: Operation {
let stringToPrint: String
init(stringToPrint: String = "I don't have manners") {
self.stringToPrint = stringToPrint
super.init()
}
override func main() {
guard !isCancelled else { return }
print(stringToPrint)
}
}
let queue = OperationQueue()
let printOperation = PrintOperation(stringToPrint: "Hello, World!")
printOperation.completionBlock = {
print("Done!")
}
queue.addOperation(printOperation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment