Swift Basics
let name = "Alice"
var age = 25
print("Hello, \(name)!")
let numbers = [1, 2, 3, 4, 5]
let doubled = numbers.map { $0 * 2 }
Functions
func greet(_ name: String) -> String {
return "Hello, \(name)!"
}
// Closures
let add = { (a: Int, b: Int) -> Int in a + b }
Summary
- Swift uses string interpolation with \()
- Closures are anonymous functions
YouTip