Created
March 29, 2018 11:10
-
-
Save lukevanin/cfda01cc957b7328a64106095d7b7e90 to your computer and use it in GitHub Desktop.
Revisions
-
lukevanin created this gist
Mar 29, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ // // 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 } } }