Skip to content

Instantly share code, notes, and snippets.

@avdyushin
Last active August 24, 2021 08:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avdyushin/6b0bf5e113bf91791d65c7a8d6915ab5 to your computer and use it in GitHub Desktop.
Save avdyushin/6b0bf5e113bf91791d65c7a8d6915ab5 to your computer and use it in GitHub Desktop.
Swift 4 hasPrefix in switch
let string = "www."
func hasPrefix(_ prefix: String) -> (String) -> Bool {
return { value in value.hasPrefix(prefix) }
}
func ~=(block: (String) -> Bool, string: String) -> Bool {
return block(string)
}
switch string {
case hasPrefix("www"):
debugPrint("Has www")
default:
()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment