Advanced-NSOperations/Earthquakes/Operations/MutuallyExclusive.swift

39 lines
1.1 KiB
Swift
Raw Permalink 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:
This file shows an example of implementing the OperationCondition protocol.
*/
import Foundation
/// A generic condition for describing kinds of operations that may not execute concurrently.
struct MutuallyExclusive<T>: OperationCondition {
static var name: String {
return "MutuallyExclusive<\(T.self)>"
}
static var isMutuallyExclusive: Bool {
return true
}
init() { }
func dependencyForOperation(operation: EarthquakeOperation) -> Operation? {
return nil
}
func evaluateForOperation(operation: EarthquakeOperation, completion: (OperationConditionResult) -> Void) {
completion(.Satisfied)
}
}
/**
The purpose of this enum is to simply provide a non-constructible
type to be used with `MutuallyExclusive<T>`.
*/
enum Alert { }
/// A condition describing that the targeted operation may present an alert.
typealias AlertPresentation = MutuallyExclusive<Alert>