Advanced-NSOperations/Earthquakes/Operations/NSOperation+Operations.swift
2022-02-16 22:16:09 -08:00

38 lines
969 B
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
Copyright (C) 2015 Apple Inc. All Rights Reserved.
See LICENSE.txt for this samples licensing information
Abstract:
A convenient extension to Foundation.NSOperation.
*/
import Foundation
extension NSOperation {
/**
Add a completion block to be executed after the `NSOperation` enters the
"finished" state.
*/
func addCompletionBlock(block: Void -> 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: [NSOperation]) {
for dependency in dependencies {
addDependency(dependency)
}
}
}