DEV Community

Agoi Abel Adeyemi
Agoi Abel Adeyemi

Posted on

4

The “let” keyword in swift

In swift, we use the let keyword to declare a constant variable, a constant is a variable that once declared, the value can not be changed.

Declaring constants

We can declare a variable in swift like below:

let myAge: Int = 27
Enter fullscreen mode Exit fullscreen mode

Notice the let keyword above, we use it to denote that myAge is a constant and should hold the integer 27. Unlike variable declared using the var keyword, we cannot change the value of a constant once it has been assigned.

A constant is very similar to a variable except it value cannot be changed when declared.

Summary

It’s important that you keep the following in mind. You can declare a constant with the let keyword, constant have the same properties as a variable (var) which include type annotation, naming convention etc., except once a value has been assigned, the value cannot be changed

Sentry blog image

The countdown to March 31 is on.

Make the switch from app center suck less with Sentry.

Read more

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.

Sentry growth stunted Image

If you are wasting time trying to track down the cause of a crash, it’s time for a better solution. Get your crash rates to zero (or close to zero as possible) with less time and effort.

Try Sentry for more visibility into crashes, better workflow tools, and customizable alerts and reporting.

Switch Tools

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay