Skip to content

Instantly share code, notes, and snippets.

@takasek
Created November 30, 2017 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takasek/dbeab7b041f5d5630ac2a0e4754a1836 to your computer and use it in GitHub Desktop.
Save takasek/dbeab7b041f5d5630ac2a0e4754a1836 to your computer and use it in GitHub Desktop.
import Foundation
struct Default: LocalizedError {
}
struct E: LocalizedError {
let errorDescription: String? = "e"
}
struct F: LocalizedError {
let failureReason: String? = "f"
}
struct R: LocalizedError {
let recoverySuggestion: String? = "r"
}
struct H: LocalizedError {
let helpAnchor: String? = "h"
}
struct EFRH: LocalizedError {
let errorDescription: String? = "e"
let failureReason: String? = "f"
let recoverySuggestion: String? = "r"
let helpAnchor: String? = "h"
}
let errors: [LocalizedError] = [
Default(), E(), F(), R(), H(), EFRH()
]
errors.forEach {
print(
"[\(type(of: $0))]",
"\n ๐Ÿ“ \($0.localizedDescription)",
"\n ๐Ÿ“Œ",
$0.errorDescription ?? "_",
$0.failureReason ?? "_",
$0.recoverySuggestion ?? "_",
$0.helpAnchor ?? "_"
)
}
/*
[Default]
๐Ÿ“ The operation couldnโ€™t be completed. (__lldb_expr_260.Default error 1.)
๐Ÿ“Œ _ _ _ _
[E]
๐Ÿ“ e
๐Ÿ“Œ e _ _ _
[F]
๐Ÿ“ The operation couldnโ€™t be completed. f
๐Ÿ“Œ _ f _ _
[R]
๐Ÿ“ The operation couldnโ€™t be completed. (__lldb_expr_260.R error 1.)
๐Ÿ“Œ _ _ r _
[H]
๐Ÿ“ The operation couldnโ€™t be completed. (__lldb_expr_260.H error 1.)
๐Ÿ“Œ _ _ _ h
[EFRH]
๐Ÿ“ e
๐Ÿ“Œ e f r h
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment