"Testing1"
Swift Literals
Definition:
Literals in Swift are hardcoded values embedded straight into your code when setting variables or constants.They represent raw data like numbers, characters, or text.
Types of Literals
1. Integer Literal: Whole numbers swift Copy Edit
let age = 30
2. Floating-point Literal: Decimal numbers swift Copy Edit
let price = 19.99
3. String Literal: Text inside quotes swift Copy Edit
let name = "Swift"
4. Boolean Literal: true or false
let isOpen = true
5. Character Literal: A single character
let letter: Character = "A"
6. Array & Dictionary Literals:
let fruits = ["Apple", "Mango"] let scores = ["Math": 95, "Science": 90]
Why Use Literals?
- Simple way to assign known values
- Improves clarity in code
- Speeds up variable initialization
Prefer Learning by Watching?
Watch these YouTube tutorials to understand GIT Tutorial visually:
What You'll Learn:
- 📌 38. Image Literal in Swift - Learn Swift For Beginners
- 📌 Swift 4 – Literals