Declare String Variable
To declare a variable of type String in Swift, use
: String after the variable name.
var company: String
Let us write a swift program, in which we declare a variable with the name
company, and declare this variable as type
String. Later, we will assign a value
"Apple" to this variable and print it.
import Foundation var company: String company = "Apple" print(company)
The type of the variable
String, because of which we could assign a String value to the variable.
We can also programmatically check the type of the variable
import Foundation var company: String print(type(of: company))
We have learnt how to declare a variable of type String in Swift.