[Swift] Constants and variables

[Swift] Constants and variables

Constants and variables are used for temporary storage of values. By saving the result of the process, you can reuse it in the subsequent process. Variables can be reassigned, but constants cannot be reassigned once.

Declaration method

The variable is var and the constant is let.

var variable name:Model name
let variable name:Model name

Substitute 3 for the variable names a and b. Declare it as an Int type.

var a:Int=3
let b:Int=3

Value assignment method

Then substitute 1 for a and b.

a=1//1
b=1//Compile error

As you can see from the result, it is possible to substitute 1 for a, but not for b.

Recommended Posts

[Swift] Constants and variables
[Programming Complete] ยง4 Variables and constants
Java and Swift comparison (1) Source control / Scope / Variables
Ruby variables and methods
[Java] Variables and types
Java programming (variables and data)
Difference between variables and instance variables
Ruby variables and functions (methods)
About instance variables and attr_ *
Java Primer Series (Variables and Types)
Organize classes, instances, and instance variables
[Swift] Advantages and disadvantages of Storyboard
Install Xcode and use Hello Swift!
Swift Network.framework Study 20200319 "Receive and Send"
[Swift] Protocol concept and definition method
[Swift] Property observers willSet and didSet
This and that of Swift corner Radius
[Swift] Mutual conversion between Int and Data
[Swift] A note about function and closure
Regarding swift conditional compilation and preprocessor directives
A Java engineer compared Swift, Kotlin, and Java.
[Swift] Implement tap and long press processing!
[Java / Swift] Comparison of Java Interface and Swift Protocol
Java basic learning content 1 (literals, variables, constants)
Java programming (static clauses and "class variables")
Output using methods and constants Learning memo
Hex and UIColor mutual conversion in Swift
progate java L1 basic summary console.log, difference between variables and constants, if statement