@@ -408,70 +408,72 @@ extension ParseError: CustomStringConvertible {
408
408
}
409
409
410
410
// MARK: Compare Errors
411
- extension Error {
411
+ public extension Error {
412
+
412
413
/**
413
- Validates if the given ParseError Code is equal to the error.
414
+ Returns the respective `ParseError` if the given ` ParseError` code is equal to the error.
414
415
415
416
**Example use case:**
416
417
~~~
417
- if error.equalsTo(.objectNotFound) {
418
- //Do stuff
418
+ if let parseError = error.equalsTo(.objectNotFound) {
419
+ print(parseError.description)
419
420
}
420
421
~~~
421
422
- parameter errorCode: A `ParseError` code to compare to.
422
423
423
- - returns: A boolean indicating wheter or not the `Error` is the `errorCode`
424
+ - returns: Returns the `ParseError` with respect to the `Error`. If the error is not a `ParseError`, returns nil.
424
425
*/
425
- public func equalsTo( _ errorCode: ParseError . Code ) -> Bool {
426
- guard let error = self as? ParseError else {
427
- return false
426
+ func equalsTo( _ errorCode: ParseError . Code ) -> ParseError ? {
427
+ guard let error = self as? ParseError ,
428
+ error. code == errorCode else {
429
+ return nil
428
430
}
429
- return error. code == errorCode
431
+ return error
430
432
}
431
433
432
434
/**
433
- Returns an optional ParseError if the given ParseError Code is equal to the error.
435
+ Validates if the given ` ParseError` code is equal to the error.
434
436
435
437
**Example use case:**
436
438
~~~
437
- if let parseError = error.equalsTo(.objectNotFound) {
438
- print(parseError.description)
439
+ if error.equalsTo(.objectNotFound) {
440
+ //Do stuff
439
441
}
440
442
~~~
441
443
- parameter errorCode: A `ParseError` code to compare to.
442
444
443
- - returns: An optional `ParseError`
445
+ - returns: A boolean indicating whether or not the `Error` is the `errorCode`.
444
446
*/
445
- public func equalsTo( _ errorCode: ParseError . Code ) -> ParseError ? {
446
- guard let error = self as? ParseError ,
447
- error. code == errorCode else {
448
- return nil
447
+ func equalsTo( _ errorCode: ParseError . Code ) -> Bool {
448
+ guard equalsTo ( errorCode) != nil else {
449
+ return false
449
450
}
450
- return error
451
+ return true
451
452
}
452
453
453
454
/**
454
- Validates if the given ParseError Codes contains the error .
455
+ Returns the respective `ParseError` if the `Error` is contained in the array of `ParseError` codes .
455
456
456
457
**Example use case:**
457
458
~~~
458
- if error.containedIn(.objectNotFound, .invalidQuery) {
459
- //Do stuff
459
+ if let parseError = error.containedIn([ .objectNotFound, .invalidQuery] ) {
460
+ print(parseError.description)
460
461
}
461
462
~~~
462
- - parameter errorCodes: A variadic amount of zero or more of `ParseError` codes to compare to.
463
+ - parameter errorCodes: An array of zero or more of `ParseError` codes to compare to.
463
464
464
- - returns: A boolean indicating wheter or not the `Error` is contained in the `errorCodes`
465
+ - returns: Returns the `ParseError` with respect to the `Error`. If the error is not a `ParseError`, returns nil.
465
466
*/
466
- public func containedIn( _ errorCodes: ParseError . Code ... ) -> Bool {
467
- guard let error = self as? ParseError else {
468
- return false
467
+ func containedIn( _ errorCodes: [ ParseError . Code ] ) -> ParseError ? {
468
+ guard let error = self as? ParseError ,
469
+ errorCodes. contains ( error. code) == true else {
470
+ return nil
469
471
}
470
- return errorCodes . contains ( error. code )
472
+ return error
471
473
}
472
474
473
475
/**
474
- Returns an optional ParseError if the given ParseError Codes contains the error .
476
+ Returns the respective ` ParseError` if the `Error` is contained in the list of `ParseError` codes .
475
477
476
478
**Example use case:**
477
479
~~~
@@ -481,18 +483,14 @@ extension Error {
481
483
~~~
482
484
- parameter errorCodes: A variadic amount of zero or more of `ParseError` codes to compare to.
483
485
484
- - returns: An optional `ParseError`
486
+ - returns: Returns the `ParseError` with respect to the `Error`. If the error is not a `ParseError`, returns nil.
485
487
*/
486
- public func containedIn( _ errorCodes: ParseError . Code ... ) -> ParseError ? {
487
- guard let error = self as? ParseError ,
488
- errorCodes. contains ( error. code) == true else {
489
- return nil
490
- }
491
- return error
488
+ func containedIn( _ errorCodes: ParseError . Code ... ) -> ParseError ? {
489
+ containedIn ( errorCodes)
492
490
}
493
491
494
492
/**
495
- Validates if the given ParseError Codes contains the error.
493
+ Validates if the given ` ParseError` codes contains the error.
496
494
497
495
**Example use case:**
498
496
~~~
@@ -502,33 +500,29 @@ extension Error {
502
500
~~~
503
501
- parameter errorCodes: An array of zero or more of `ParseError` codes to compare to.
504
502
505
- - returns: A boolean indicating wheter or not the `Error` is contained in the `errorCodes`
503
+ - returns: A boolean indicating whether or not the `Error` is contained in the `errorCodes`.
506
504
*/
507
- public func containedIn( _ errorCodes: [ ParseError . Code ] ) -> Bool {
508
- guard let error = self as? ParseError else {
505
+ func containedIn( _ errorCodes: [ ParseError . Code ] ) -> Bool {
506
+ guard containedIn ( errorCodes ) != nil else {
509
507
return false
510
508
}
511
- return errorCodes . contains ( error . code )
509
+ return true
512
510
}
513
511
514
512
/**
515
- Returns an optional ParseError if the given ParseError Codes contains the error.
513
+ Validates if the given ` ParseError` codes contains the error.
516
514
517
515
**Example use case:**
518
516
~~~
519
- if let parseError = error.containedIn([ .objectNotFound, .invalidQuery] ) {
520
- print(parseError.description)
517
+ if error.containedIn(.objectNotFound, .invalidQuery) {
518
+ //Do stuff
521
519
}
522
520
~~~
523
- - parameter errorCodes: An array of zero or more of `ParseError` codes to compare to.
521
+ - parameter errorCodes: A variadic amount of zero or more of `ParseError` codes to compare to.
524
522
525
- - returns: An optional `ParseError`
523
+ - returns: A boolean indicating whether or not the `Error` is contained in the `errorCodes`.
526
524
*/
527
- public func containedIn( _ errorCodes: [ ParseError . Code ] ) -> ParseError ? {
528
- guard let error = self as? ParseError ,
529
- errorCodes. contains ( error. code) == true else {
530
- return nil
531
- }
532
- return error
525
+ func containedIn( _ errorCodes: ParseError . Code ... ) -> Bool {
526
+ containedIn ( errorCodes)
533
527
}
534
528
}
0 commit comments