2
我有以下枚舉如何從此枚舉中獲取CustomStringConvertible說明?
enum Properties: CustomStringConvertible {
case binaryOperation(BinaryOperationProperties),
brackets(BracketsProperties),
chemicalElement(ChemicalElementProperties),
differential(DifferentialProperties),
function(FunctionProperties),
number(NumberProperties),
particle(ParticleProperties),
relation(RelationProperties),
stateSymbol(StateSymbolProperties),
symbol(SymbolProperties)
}
和結構都這個樣子
struct BinaryOperationProperties: Decodable, CustomStringConvertible {
let operation: String
var description: String { return operation }
}
那麼,如何讓該枚舉符合CustomStringConvertible
?我嘗試了一個簡單的getter,但很明顯,它調用自己,我想調用特定的結構的代替。
獎勵積分:是不是有一個名稱定義的枚舉?
我結束了使用第一個選項,因爲輸出對於我所需要的更加緊湊,但是感謝您徹底! – Morpheu5