
์ด๊ฑฐํ (Enumerations) enum CompassPoint { case north case south case east case west } enum Planet { case mercury, venus, earth, mars, jupiter, saturn, uranus, neptune } ์ฝค๋ง๋ก ๊ตฌ๋ถํ์ฌ ํ์ค๋ก ํ๊ธฐํ ์ ์๋ค. enum Beverage: CaseIterable { case coffee, tea, juice } let numberOfChoices = Beverage.allCases.count ์ด๊ฑฐํ ์ด๋ฆ ๋ค์ : CaseIterable ์ ์์ฑ → allCases ํ๋กํผํฐ๋ array๋ก ๊ด๋ จ ๋ฉ์๋ ์ฌ์ฉ ๊ฐ๋ฅ ์ฐ๊ด๋ ๊ฐ (Associated Values) enum Barcode {..

ํด๋ก์ (Closures) ์ ์ญํจ์ = ์ด๋ฆ์ ๊ฐ์ง๊ณ ์ด๋ ํ ๊ฐ๋ ์บก์ฒํ์ง ์๋ ํด๋ก์ ์ค์ฒฉ ํจ์ = ์ด๋ฆ์ ๊ฐ์ง๊ณ ๋๋ฌ์ผ ํจ์๋ก ๋ถํฐ ๊ฐ์ ์บก์ฒํ ์ ์๋ ํด๋ก์ ์ฃผ๋ณ ์ปจํ ์คํธ์์ ๊ฐ์ ์บก์ฒํ ์ ์๋ ์์ฝ๋ ๊ตฌ๋ฌธ = ์ด๋ฆ์ด ์๋ ํด๋ก์ (Unnamed Closure) ํด๋ก์ ์ ํ๋ผ๋ฏธํฐ → inout ํ๋ผ๋ฏธํฐ ์ผ ์ ์์ง๋ง ๊ธฐ๋ณธ๊ฐ์ ๊ฐ์ง ์ ์๋ค. let names = ["Chris", "Alex", "Ewa", "Barry", "Daniella"] func backward(_ s1: String, _ s2: String) -> Bool { return s1 > s2 } var reversedNames = names.sorted(by: backward) // backwardํจ์๋ฅผ ํด๋ก์ ๋ก ํํ rever..

Functions With an Implicit Return func greeting(for person: String) -> String { "Hello, " + person + "!" } ์ ์ฒด ๋ณธ๋ฌธ์ด ํ์ค๋ก ํํ์ด ๋๋ค๋ฉด returnํค์๋ ์๋ต ๊ฐ๋ฅ Specifying Argument Labels func greet(person: String, from hometown: String) -> String { return "Hello \\(person)! Glad you could visit from \\(hometown)." } print(greet(person: "Bill", from: "Cupertino")) ํจ์ ๋ด๋ถ์์ ์ฌ์ฉํ ์ธ์ ์ด๋ฆ ์ง์ ์ด ๊ฐ๋ฅํ๋ค. ๊ฐ๋ณ ํ๋ผ๋ฏธํฐ (Variadic Para..

for๋ฌธ์ stride ๋ฉ์๋ for i in stride(from: 0, to: 10, by: 2) { print(i) // 0, 2, 4, 6, 8 } for i in stride(from: 0, through: 10, by: 2) { print(i) // 0, 2, 4, 6, 8, 10 } // reverseํ๊ณ ์ถ์ ๋ ์ธ ์ ์๋ค. for i in stride(from: 3, through: 0, by: -1) { print(i) // 3, 2, 1, 0 } 1์ฉ ์ฆ๊ฐ๊ฐ ์๋ ์ํ๋ ์ซ์๋งํผ ์ฆ๊ฐ ์ํค๊ณ ์ถ์ ๋ ์ฌ์ฉ to : toํ๋ผ๋ฏธํฐ์ ์๋ ์๋ฅผ ์ ์ธํ๋ค. through: throughํ๋ผ๋ฏธํฐ์ ์๋ ์ ํฌํจํ๋ค. repeat while ๊ตฌ๋ฌธ var num = 1 repeat { num +..