Google News
logo
Swift - Interview Questions
Explain how to create constant in Swift programming?
We can create constant in Swift programming by declaring a ‘let’ keyword. Below is the example where we use declare street as a constant in lieu of a variable. For this, we have to use let keyword :
let street: String = “7th Avenue”
var number: Int
street = “Side Street”
number = 10

 

We cannot change the value of constant in Swift. If we try to update the first line of the code, the Xcode will show an error for a simple reason. To change the value of the street, we can comment on the given line, so that it will not create any type of error.
let street: String = “7th Avenue”
var number: Int
// street = “Side Street”
number = 10
Advertisement