Skip to content

Commit b885391

Browse files
committed
nits on comments and structure
1 parent d50a796 commit b885391

File tree

1 file changed

+45
-51
lines changed

1 file changed

+45
-51
lines changed

Sources/ParseSwift/Types/ParseError.swift

Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -408,70 +408,72 @@ extension ParseError: CustomStringConvertible {
408408
}
409409

410410
// MARK: Compare Errors
411-
extension Error {
411+
public extension Error {
412+
412413
/**
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.
414415

415416
**Example use case:**
416417
~~~
417-
if error.equalsTo(.objectNotFound) {
418-
//Do stuff
418+
if let parseError = error.equalsTo(.objectNotFound) {
419+
print(parseError.description)
419420
}
420421
~~~
421422
- parameter errorCode: A `ParseError` code to compare to.
422423

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.
424425
*/
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
428430
}
429-
return error.code == errorCode
431+
return error
430432
}
431433

432434
/**
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.
434436

435437
**Example use case:**
436438
~~~
437-
if let parseError = error.equalsTo(.objectNotFound) {
438-
print(parseError.description)
439+
if error.equalsTo(.objectNotFound) {
440+
//Do stuff
439441
}
440442
~~~
441443
- parameter errorCode: A `ParseError` code to compare to.
442444

443-
- returns: An optional `ParseError`
445+
- returns: A boolean indicating whether or not the `Error` is the `errorCode`.
444446
*/
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
449450
}
450-
return error
451+
return true
451452
}
452453

453454
/**
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.
455456

456457
**Example use case:**
457458
~~~
458-
if error.containedIn(.objectNotFound, .invalidQuery) {
459-
//Do stuff
459+
if let parseError = error.containedIn([.objectNotFound, .invalidQuery]) {
460+
print(parseError.description)
460461
}
461462
~~~
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.
463464

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.
465466
*/
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
469471
}
470-
return errorCodes.contains(error.code)
472+
return error
471473
}
472474

473475
/**
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.
475477

476478
**Example use case:**
477479
~~~
@@ -481,18 +483,14 @@ extension Error {
481483
~~~
482484
- parameter errorCodes: A variadic amount of zero or more of `ParseError` codes to compare to.
483485

484-
- returns: An optional `ParseError`
486+
- returns: Returns the `ParseError` with respect to the `Error`. If the error is not a `ParseError`, returns nil.
485487
*/
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)
492490
}
493491

494492
/**
495-
Validates if the given ParseError Codes contains the error.
493+
Validates if the given `ParseError` codes contains the error.
496494

497495
**Example use case:**
498496
~~~
@@ -502,33 +500,29 @@ extension Error {
502500
~~~
503501
- parameter errorCodes: An array of zero or more of `ParseError` codes to compare to.
504502

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`.
506504
*/
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 {
509507
return false
510508
}
511-
return errorCodes.contains(error.code)
509+
return true
512510
}
513511

514512
/**
515-
Returns an optional ParseError if the given ParseError Codes contains the error.
513+
Validates if the given `ParseError` codes contains the error.
516514

517515
**Example use case:**
518516
~~~
519-
if let parseError = error.containedIn([.objectNotFound, .invalidQuery]) {
520-
print(parseError.description)
517+
if error.containedIn(.objectNotFound, .invalidQuery) {
518+
//Do stuff
521519
}
522520
~~~
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.
524522

525-
- returns: An optional `ParseError`
523+
- returns: A boolean indicating whether or not the `Error` is contained in the `errorCodes`.
526524
*/
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)
533527
}
534528
}

0 commit comments

Comments
 (0)