mirror of
https://github.com/samsonjs/Advanced-NSOperations.git
synced 2026-03-25 08:25:47 +00:00
38 lines
969 B
Swift
38 lines
969 B
Swift
/*
|
||
Copyright (C) 2015 Apple Inc. All Rights Reserved.
|
||
See LICENSE.txt for this sample’s licensing information
|
||
|
||
Abstract:
|
||
A convenient extension to Foundation.Operation.
|
||
*/
|
||
|
||
import Foundation
|
||
|
||
extension Operation {
|
||
/**
|
||
Add a completion block to be executed after the `Operation` enters the
|
||
"finished" state.
|
||
*/
|
||
func addCompletionBlock(block: @escaping () -> Void) {
|
||
if let existing = completionBlock {
|
||
/*
|
||
If we already have a completion block, we construct a new one by
|
||
chaining them together.
|
||
*/
|
||
completionBlock = {
|
||
existing()
|
||
block()
|
||
}
|
||
}
|
||
else {
|
||
completionBlock = block
|
||
}
|
||
}
|
||
|
||
/// Add multiple depdendencies to the operation.
|
||
func addDependencies(dependencies: [Operation]) {
|
||
for dependency in dependencies {
|
||
addDependency(dependency)
|
||
}
|
||
}
|
||
}
|