associated-value

How to make a Swift enum with associated values equatable

泄露秘密 提交于 2021-02-15 09:12:27
问题 I have an enum of associated values which I would like to make equatable for testing purposes, but do not know how this pattern would work with an enum case with more than one argument. For example, summarised below I know the syntax for making heading equatable. How would this work for options, which contains multiple values of different types? enum ViewModel { case heading(String) case options(id: String, title: String, enabled: Bool) } func ==(lhs: ViewModel, rhs: ViewModel) -> Bool {

How to make a Swift enum with associated values equatable

浪尽此生 提交于 2021-02-15 09:11:11
问题 I have an enum of associated values which I would like to make equatable for testing purposes, but do not know how this pattern would work with an enum case with more than one argument. For example, summarised below I know the syntax for making heading equatable. How would this work for options, which contains multiple values of different types? enum ViewModel { case heading(String) case options(id: String, title: String, enabled: Bool) } func ==(lhs: ViewModel, rhs: ViewModel) -> Bool {