Created
September 23, 2021 00:30
-
-
Save 0xLeif/80edced1c92bb8f088963fe03cf5e22d to your computer and use it in GitHub Desktop.
case let vs case .(let)
This file contains 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 characters
enum Something { | |
case a(value: String) | |
case b(value: String, times: Int) | |
case c(value: String, times: Int, isOn: Bool) | |
} | |
let a: Something = .a(value: "A Value") | |
let b: Something = .b(value: "B Value", times: 27) | |
let c: Something = .c(value: "C Value", times: 27, isOn: false) | |
let something: Something = b | |
if case .a = something { | |
print("Ignore the value") | |
} else if case .b(let value, let times) = something { | |
print(String(repeating: value, count: times)) | |
} else if case let .c(value, times, isOn) = something { | |
if isOn { | |
print(String(repeating: value, count: times)) | |
} | |
} | |
switch something { | |
case .a: | |
print("Ignore the value") | |
case .b(let value, let times) : | |
print(String(repeating: value, count: times)) | |
case let .c(value, times, isOn): | |
if isOn { | |
print(String(repeating: value, count: times)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment