Advanced-NSOperations/Earthquakes/Operations/PassbookCondition.swift

43 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.
*/
#if os(iOS)
import PassKit
/// A condition for verifying that Passbook exists and is accessible.
struct PassbookCondition: OperationCondition {
static let name = "Passbook"
static let isMutuallyExclusive = false
init() { }
func dependencyForOperation(operation: EarthquakeOperation) -> Operation? {
/*
There's nothing you can do to make Passbook available if it's not
on your device.
*/
return nil
}
func evaluateForOperation(operation: EarthquakeOperation, completion: (OperationConditionResult) -> Void) {
if PKPassLibrary.isPassLibraryAvailable() {
completion(.Satisfied)
}
else {
let error = NSError(code: .ConditionFailed, userInfo: [
OperationConditionKey: type(of: self).name
])
completion(.Failed(error))
}
}
}
#endif