Skip to content

Instantly share code, notes, and snippets.

@deda9
Created June 7, 2018 22:50
Show Gist options
  • Save deda9/c7da68195ba82ce3f7880deca3101609 to your computer and use it in GitHub Desktop.
Save deda9/c7da68195ba82ce3f7880deca3101609 to your computer and use it in GitHub Desktop.
How to create Dependencies for NSOperationBlock in swift
let operationQueue = OperationQueue()
let op0 = BlockOperation()
op0.completionBlock = {
print("op0 completionBlock")
}
op0.addExecutionBlock {
print("op0 executionBlock #1")
}
op0.addExecutionBlock {
print("op0 executionBlock #2")
}
op0.queuePriority = .veryHigh
let op1 = BlockOperation()
op1.addDependency(op0)
op1.completionBlock = {
print("op1 completionBlock")
}
op1.addExecutionBlock {
print("op1 executionBlock")
}
let op2 = BlockOperation()
op2.addDependency(op1)
op2.completionBlock = {
print("op2 completionBlock")
}
op2.addExecutionBlock {
print("op2 executionBlock")
}
operationQueue.addOperations([op0, op1, op2], waitUntilFinished: true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment