Skip to content

Instantly share code, notes, and snippets.

@colemancda
Created April 19, 2019 04:32
Show Gist options
  • Save colemancda/9f80ff08505d96821380c0b74622e58c to your computer and use it in GitHub Desktop.
Save colemancda/9f80ff08505d96821380c0b74622e58c to your computer and use it in GitHub Desktop.
Print all CocoaError messages
import Foundation
var errors = [CocoaError: String]()
for code in 0 ... 4866 {
let error = CocoaError(CocoaError.Code(rawValue: code))
if let reason = error._nsError.localizedFailureReason {
errors[error] = reason
}
}
print("private extension CocoaError {")
print(" static let errorMessages = [")
errors
.sorted(by: { $0.key.code.rawValue < $1.key.code.rawValue })
.forEach { print(" Code(rawValue: \($0.key.code.rawValue)): \"\($0.value)\",") }
print(" ]")
print("}")
@colemancda
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment