0
letを使用するのではなく、文字列を切り替えるときに、特定の列挙型をrawValueで初期化できるかどうかテストできますか?Swift - switch文の文字列からenumを初期化する
switch currency {
case let fiatCurrency as Fiat:
return getFiatFormatting(for: value, fiatCurrency: fiatCurrency)
case let blockchain as Blockchain:
return getCryptoFormatting(for: value, blockchain: blockchain)
case let token as Token:
return getTokenFormatting(for: value, token: token)
default:
return nil
}
ありがとう:
static func getCurrency(from code: String) -> Currency? {
if let fiatCurrency = Fiat(rawValue: code) {
return fiatCurrency
} else if let cryptoCurrency = Blockchain(rawValue: code) {
return cryptoCurrency
} else {
return nil
}
}
これはcurrency
は私の通貨プロトコルに準拠キャストを入力するために同様のかもしれません!
間違いなく、それが連続して使用できることに気付かなかった。 –