我正在编写一个课程,让用户可以选择在从我们的应用发送电子邮件时选择使用哪个电子邮件应用。
我正在尝试执行以下操作,但会收到警告,因为我已指定default
。 default
就在那里,因为我想阻止未来的开发人员使用默认设置,而不是为他们添加的任何客户端添加案例。
private enum EmailApp {
case appleMail
case gmail
case outlook
typealias EmailAppConfiguration = (title: String, scheme: String?, path: String?)
var configuration: EmailAppConfiguration {
switch self {
case .appleMail:
return ("Apple Mail", nil, nil)
case .gmail:
return ("Gmail", "googlegmail://", "co")
case .outlook:
return ("MS Outlook", "ms-outlook://", "compose")
default:
preconditionFailure("Unhandled email client. DO NOT use the default. Explicitly define the configuration when you add a new app.")
}
}
}
我不喜欢这个警告。我可以在开关前放一个guard
来做前提条件的失败,但它也会很难看。你会做什么?
答案 0 :(得分:0)
抛出错误或更改默认设置?不要提供您不喜欢使用的功能