Advanced-NSOperations/Earthquakes/Operations/OperationErrors.swift

31 lines
842 B
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 defines the error codes and convenience functions for interacting with Operation-related errors.
*/
import Foundation
let OperationErrorDomain = "OperationErrors"
enum OperationErrorCode: Int {
case ConditionFailed = 1
case ExecutionFailed = 2
}
extension NSError {
convenience init(code: OperationErrorCode, userInfo: [String: Any]? = nil) {
self.init(domain: OperationErrorDomain, code: code.rawValue, userInfo: userInfo)
}
}
// This makes it easy to compare an `NSError.code` to an `OperationErrorCode`.
func ==(lhs: Int, rhs: OperationErrorCode) -> Bool {
return lhs == rhs.rawValue
}
func ==(lhs: OperationErrorCode, rhs: Int) -> Bool {
return lhs.rawValue == rhs
}