Mobile15 Loops for in let platforms = ["iOS", "macOS", "tvOS", "watchOS"] for os in platforms { print("Swift works great on \(os).") } Swift works great on iOS. Swift works great on macOS. Swift works great on tvOS. Swift works great on watchOS. // 5를 포함 for i in 1...5 { print("Counting from 1 through 5: \(i)") } // 5를 미포함 for i in 1.. 2024. 2. 14. switch enum enum Weather { case sun, rain, wind, snow, unknown } let forecast = Weather.sun switch forecast { case .sun: print("It should be a nice day.") case .rain: print("Pack an umbrella.") case .wind: print("Wear something warm") case .snow: print("School is cancelled.") case .unknown: print("Our forecast generator is broken!") } String let place = "Metropolis" switch place { case "Gotham": print(.. 2024. 2. 14. String 선언 + let first = "Hello, " let second = "world" let greeting = first + second 더블 쿼테이션 let quote = "Then he tapped a sign saying \"Believe\" and walked away." 문자열에 다른 변수를 포함 let name = "Taylor" let age = 26 let message = "Hello, my name is \(name) and I'm \(age) years old." print(message) * \(변수) : 값이 아니라 변수자체를 참조 print("5 x 5 is \(5 * 5)") 숫자를 문자로 변환 let number = 11 let missionMessage = "Apollo .. 2024. 2. 8. enum 선언 enum Weekday { case monday case tuesday case wednesday case thursday case friday } or enum Weekday { case monday, tuesday, wednesday, thursday, friday } 변수 var day = Weekday.monday 2024. 2. 7. 이전 1 2 3 4 다음