Kurdtvs-Live-Kurdish-TV-Kur.../Mastodon/Extension/UIAlertController.swift

38 lines
876 B
Swift
Raw Normal View History

2021-02-03 09:01:08 +01:00
//
// UIAlertController.swift
// Mastodon
//
import UIKit
// Reference:
// https://nshipster.com/swift-foundation-error-protocols/
extension UIAlertController {
convenience init(
_ error: Error,
preferredStyle: UIAlertController.Style
) {
let title: String
let message: String?
if let error = error as? LocalizedError {
title = error.errorDescription ?? "Unknown Error"
message = [
error.failureReason,
error.recoverySuggestion
]
.compactMap { $0 }
.joined(separator: " ")
} else {
title = "Internal Error"
message = error.localizedDescription
}
self.init(
title: title,
message: message,
preferredStyle: preferredStyle
)
}
}