How to use switch statement with strings in Swift

1 Answer

0 votes
import Foundation

let str = "Swift"

switch str {
    case "Foo":
        print("Foo")
    case "Wii":
        print("Wii")
    case "Swift":
        print("Swift")
    case "YYI":
        print("YYI")
    default:
        print("No match found.")
}



/*
run:

Swift

*/

 



answered Jul 1, 2025 by avibootz

Related questions

1 answer 200 views
1 answer 154 views
154 views asked Feb 10, 2021 by avibootz
...