In Swift, you can use the 'hasPrefix' method of the String class to check if a string starts with a specific prefix.
In this example,
func startsWithPrefix(_ str: String, _ prefix: String) -> Bool {
return str.hasPrefix(prefix)
}
let str = "Hello World"
let prefix = "Hello"
let startsWith = startsWithPrefix(str, prefix)
print("String starts with prefix '\(prefix)': \(startsWith)")
String starts with prefix 'Hello': true
In this tutorial, we learned How to Check if String starts with Specific Prefix in Swift language with well detailed examples.