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…

Post a Comment