// // Example showing how to add Equatable protocol conformance to a complex enum using a switch statement. // // Useful if you need to compare two enums, e.g: // let a = ApplicationViewState.content("foo") // let b = ApplicationViewState.connectionError // let c = ApplicationViewState.content("foo" // a == b // false // enum ApplicationViewState { case sync case content(String) case login case connectionError case versionError(URL) } extension ApplicationViewState: Equatable { static func ==(lhs: ApplicationViewState, rhs: ApplicationViewState) -> Bool { switch (lhs, rhs) { case (.sync, .sync): return true case (.content(let lhs), .content(let rhs)): return lhs == rhs case (.login, .login): return true case (.connectionError, .connectionError): return true case (.versionError(let lhs), .versionError(let rhs)): return lhs == rhs default: return false } } }