|
1 |
| -**Published by Arunprasadh C on 21 Apr 2022** • *Last Updated on 27 Apr 2022* |
| 1 | +**Published by Arunprasadh C on 21 Apr 2022** • *Last Updated on 06 May 2022* |
2 | 2 |
|
3 | 3 | ## Variables, Literals and Constants in Swift
|
4 | 4 | ### Literals
|
@@ -32,19 +32,26 @@ var word:String
|
32 | 32 | // Some statements
|
33 | 33 | word = "Hello"
|
34 | 34 | ```
|
35 |
| -#### Declaring Multiple Variables on a single line |
36 |
| -Multiple variables can be declared without initialization in a single line provided that the variables are annotated with their types. |
| 35 | +#### Defining Multiple Variables on a single line |
| 36 | +Multiple variables can be declared/defined with/without initialization in a single line provided that the variables are annotated with their types. |
37 | 37 |
|
38 | 38 | **Syntax :**
|
39 | 39 | ```swift
|
40 |
| -var v1:DataType1, v2:DataType2, v3:DataType3, ... |
| 40 | +var v1:DataType1 = optInitialValue1, v2:DataType2 = optInitialValue1, v3:DataType3 = optInitialValue1, ... |
41 | 41 | ```
|
42 | 42 | **Example :**
|
43 | 43 | ```swift
|
44 |
| -var name: String, age: Int, native: String |
| 44 | +var name: String = "Kris", age: Int = 22, native: String = "Chennai" |
| 45 | +print("\(name), who is \(age) years old, is from \(native).") |
45 | 46 | ```
|
| 47 | + |
| 48 | +**Output :** |
| 49 | +``` |
| 50 | +Kris, who is 22 years old, is from Chennai. |
| 51 | +``` |
| 52 | + |
46 | 53 | #### Initializing/Assigning values to Multiple Variables using Tuple Syntax
|
47 |
| -Multiple variables can be initialized/assigned to values at once using the Tuple Syntax: |
| 54 | +Multiple variables can be reassigned to values at once using the Tuple Syntax: |
48 | 55 |
|
49 | 56 | **Syntax :**
|
50 | 57 | ```swift
|
|
0 commit comments