@@ -144,7 +144,7 @@ open class NSError : NSObject, NSCopying, NSSecureCoding, NSCoding {
144
144
case NSPOSIXErrorDomain:
145
145
return String ( cString: strerror ( Int32 ( code) ) , encoding: . ascii)
146
146
case NSCocoaErrorDomain:
147
- return nil
147
+ return CocoaError . errorMessages [ CocoaError . Code ( rawValue : code ) ]
148
148
case NSURLErrorDomain:
149
149
return nil
150
150
default :
@@ -610,7 +610,7 @@ public struct CocoaError : _BridgedStoredNSError {
610
610
public static var _nsErrorDomain : String { return NSCocoaErrorDomain }
611
611
612
612
/// The error code itself.
613
- public struct Code : RawRepresentable , _ErrorCodeProtocol {
613
+ public struct Code : RawRepresentable , Hashable , _ErrorCodeProtocol {
614
614
public typealias _ErrorType = CocoaError
615
615
616
616
public let rawValue : Int
@@ -670,6 +670,43 @@ public struct CocoaError : _BridgedStoredNSError {
670
670
}
671
671
}
672
672
673
+ internal extension CocoaError {
674
+ static let errorMessages = [
675
+ Code ( rawValue: 4 ) : " The file doesn’t exist. " ,
676
+ Code ( rawValue: 255 ) : " The file couldn’t be locked. " ,
677
+ Code ( rawValue: 257 ) : " You don’t have permission. " ,
678
+ Code ( rawValue: 258 ) : " The file name is invalid. " ,
679
+ Code ( rawValue: 259 ) : " The file isn’t in the correct format. " ,
680
+ Code ( rawValue: 260 ) : " The file doesn’t exist. " ,
681
+ Code ( rawValue: 261 ) : " The specified text encoding isn’t applicable. " ,
682
+ Code ( rawValue: 262 ) : " The specified URL type isn’t supported. " ,
683
+ Code ( rawValue: 263 ) : " The item is too large. " ,
684
+ Code ( rawValue: 264 ) : " The text encoding of the contents couldn’t be determined. " ,
685
+ Code ( rawValue: 513 ) : " You don’t have permission. " ,
686
+ Code ( rawValue: 514 ) : " The file name is invalid. " ,
687
+ Code ( rawValue: 516 ) : " A file with the same name already exists. " ,
688
+ Code ( rawValue: 517 ) : " The specified text encoding isn’t applicable. " ,
689
+ Code ( rawValue: 518 ) : " The specified URL type isn’t supported. " ,
690
+ Code ( rawValue: 640 ) : " There isn’t enough space. " ,
691
+ Code ( rawValue: 642 ) : " The volume is read only. " ,
692
+ Code ( rawValue: 1024 ) : " The value is invalid. " ,
693
+ Code ( rawValue: 2048 ) : " The value is invalid. " ,
694
+ Code ( rawValue: 3072 ) : " The operation was cancelled. " ,
695
+ Code ( rawValue: 3328 ) : " The requested operation is not supported. " ,
696
+ Code ( rawValue: 3840 ) : " The data is not in the correct format. " ,
697
+ Code ( rawValue: 3841 ) : " The data is in a format that this application doesn’t understand. " ,
698
+ Code ( rawValue: 3842 ) : " An error occurred in the source of the data. " ,
699
+ Code ( rawValue: 3851 ) : " An error occurred in the destination for the data. " ,
700
+ Code ( rawValue: 3852 ) : " An error occurred in the content of the data. " ,
701
+ Code ( rawValue: 4353 ) : " The file is not available on iCloud yet. " ,
702
+ Code ( rawValue: 4354 ) : " There isn’t enough space in your account. " ,
703
+ Code ( rawValue: 4355 ) : " The iCloud servers might be unreachable or your settings might be incorrect. " ,
704
+ Code ( rawValue: 4864 ) : " The data isn’t in the correct format. " ,
705
+ Code ( rawValue: 4865 ) : " The data is missing. " ,
706
+ Code ( rawValue: 4866 ) : " The data isn’t in the correct format. "
707
+ ]
708
+ }
709
+
673
710
public extension CocoaError {
674
711
private var _nsUserInfo : [ AnyHashable : Any ] {
675
712
return _nsError. userInfo
0 commit comments