분류 전체보기128 예외처리 do { let result = try someRiskyWork() } catch { print("Handle errors here") } 2024. 2. 14. function func printHello(name : String) { print("Hello \(name)") } printHello( name : "Kitty" ) or printHello("Kitty") func printHello(nick name : String) { print("Hello \(name)") } printHello( nick : "Kitty" ) ⭐️ 외부용 파라미터로 nick 을 내부용으로 name 을 정의 func printHello(name: String) -> Bool { print("Hello\(name)") return true } let b = printHello( name : "Kitty" ) func printHello(name : String) -> String { "Hel.. 2024. 2. 14. 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. 이전 1 ··· 8 9 10 11 12 13 14 ··· 32 다음