Skip to content

Commit

Permalink
improve code for CustomNSError example
Browse files Browse the repository at this point in the history
Defining the function in the property would create a new function every time the `errorUserInfo` property is accessed.
  • Loading branch information
koenpunt authored Dec 7, 2023
1 parent 4d18a49 commit 05f3fd3
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/platform-includes/capture-error/apple.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ enum MyCustomError: Error {

extension MyCustomError: CustomNSError {
var errorUserInfo: [String : Any] {
func getDebugDescription() -> String {
switch self {
case .indexOutOfBounds:
return "indexOutOfBounds"
case .enumeratingWhileMutating:
return "enumeratingWhileMutating"
}
}

return [NSDebugDescriptionErrorKey: getDebugDescription()]
}

private func getDebugDescription() -> String {
switch self {
case .indexOutOfBounds:
return "indexOutOfBounds"
case .enumeratingWhileMutating:
return "enumeratingWhileMutating"
}
}
}
```

Expand Down

0 comments on commit 05f3fd3

Please sign in to comment.