File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -274,6 +274,38 @@ public protocol CustomNSError : Error {
274
274
var errorUserInfo : [ String : Any ] { get }
275
275
}
276
276
277
+ public extension CustomNSError {
278
+ /// Default domain of the error.
279
+ static var errorDomain : String {
280
+ return String ( reflecting: self )
281
+ }
282
+
283
+ /// The error code within the given domain.
284
+ var errorCode : Int {
285
+ return _swift_getDefaultErrorCode ( self )
286
+ }
287
+
288
+ /// The default user-info dictionary.
289
+ var errorUserInfo : [ String : Any ] {
290
+ return [ : ]
291
+ }
292
+ }
293
+
294
+ extension
295
+ where Self: RawRepresentable , Self . RawValue : SignedInteger {
296
+ // The error code of Error with integral raw values is the raw value.
297
+ public var errorCode : Int {
298
+ return numericCast ( self . rawValue)
299
+ }
300
+ }
301
+
302
+ extension CustomNSError where Self: RawRepresentable , Self. RawValue: UnsignedInteger {
303
+ // The error code of Error with integral raw values is the raw value.
304
+ public var errorCode : Int {
305
+ return numericCast ( self . rawValue)
306
+ }
307
+ }
308
+
277
309
public extension Error where Self : CustomNSError {
278
310
/// Default implementation for customized NSErrors.
279
311
var _domain : String { return Self . errorDomain }
You can’t perform that action at this time.
0 commit comments