Swiftly

Swift 5.1 references for busy coders

Print

The print method is used to display a value on the console.

print("Hello world!")
// Prints "Hello world!"

Printing variables

let mySentence = "I am from China."
print(mySentence)
// Prints "I am from China."

let life = 42
print(life)
// Prints "42"

String interpolation

let country = "China"
print("I am from \(country).")
// Prints "I am from China."

let appleCount = 5
print("I have \(appleCount) apples.")
// Prints "I have 5 apples."