Lesson Notes and Walkthrough
A data type tells Swift what kind of value a variable stores. Types help Swift prevent invalid operations and keep your app behavior predictable.
Common Types You Will Use First
String: text, for example names or messages.Int: whole numbers, for example score or age.Double: decimal numbers, for example price or distance.Bool: true/false values, for exampleisLoggedIn.
Step-by-Step Example
var studentName: String = "Lina"
var lessonCount: Int = 4
var progress: Double = 0.75
var isComplete: Bool = false
print(studentName)
print(lessonCount)
print(progress)
print(isComplete)Why Type Safety Helps Beginners
If you accidentally do something invalid, Swift warns you early. For example, adding text to an Int without conversion will fail at compile time instead of causing hidden bugs later.
Quick Rule of Thumb
- If it has letters, start with
String. - If it is a whole count, use
Int. - If it needs decimals, use
Double. - If it is yes/no, use
Bool.