Create in Swift

Find this useful? Support us: Star on GitHub 6
Category: String | Language: Swift

In Swift, a string is simply a sequence of characters enclosed in double quotes "".

Here's an example of how you can create a string in Swift:

let greeting = "Hello, world!"

This creates a constant named greeting which contains the string "Hello, world!".

You can also create a string using string interpolation. String interpolation is the process of embedding values inside a string literal by wrapping them in a pair of parentheses preceded by a backslash "\".

let name = "John"
let message = "Hello, \(name)!"

This creates a string variable named message which contains the string "Hello, John!".

There are many other ways to create a string in Swift including using a string initializer, appending strings, and more.