Swift-Cheatsheet
๐ Hello World import Foundation
print("Hello, World!") ๐ก Tip: In Swift, print() automatically adds a newline — no semicolon needed! ๐ฆ Variables & Constants var name = "Maxon" // variable (mutable)
let pi = 3.14159 // constant (immutable)
var age: Int = 25 // explicit type ๐ก Tip: Use let for constants — Swift prefers immutability. ๐ข Data Types let isSwiftFun: Bool = true
let score: Int = 100
let temperature: Double = 36.6
let initial: Character = "S"
let message: String = "Swift Rocks!" ๐ก Tip: Swift is strongly typed, but supports type inference. ๐ Control Flow for i in 1...5 {
if i % 2 == 0 {
print("\(i) is Even")
} else {
print("\(i) is Odd")
}
}
var grade = "B"
switch grade {
case "A": print("Excellent")
case "B": print("Good")
default: print("Keep trying!")
} ๐ก Tip: switch in Swift must be exhaustive — cover all cases. ๐งฎ Func…