λμ μ°μ°μ (Assignment Operator)
if x = y { // νλ¦° λ¬Έλ², λμ
μ°μ°μλ κ°μ 리ν΄νμ§ μμ
}
μ°μ μ°μ°μ (Arithmetic Operators)
1 + 2 // equals 3
5 - 3 // equals 2
2 * 3 // equals 6
10.0 / 2.5 // equals 4.0
- κ°μ΄ μ€λ²νλ‘μ° λλ κ²μ νλ½νμ§ μμ
λλ¨Έμ§ μ°μ°μ (Remainder Operator)
-9 % 4 // -9 = (4*-2) + (-1)
- a = (b x some multiplier) + remainder κ³μ°μμΌλ‘ λλ¨Έμ§ κ³μ°
λ¨ν λΊμ μ°μ°μ (Unary Minus Operator) & λ¨ν λ§μ μ°μ°μ (Unary Plus Operator)
// λ¨ν λΊμ
μ°μ°μ
let three = 3
let minusThree = -three // -3
// λ¨ν λ§μ
μ°μ°μ
let minusSix = -6
let alsoMinusSix = +minusSix // -6 (κ° λ³κ²½μ΄ μμ)
- λ¨ν λ§μ μ°μ°μλ μ€μ λ‘ μλ¬΄λ° λμμ νμ§ μλλ€.
- μμμ λ¨ν λΊμ μ°μ°μλ₯Ό μ¬μ©ν λ μμμ λμΉμ μν΄ μ¬μ©ν μ μλ€
λΉκ΅ μ°μ°μ (Comparison Operators)
(1, "zebra") < (2, "apple") // 1λ³΄λ€ 2κ° ν¬κΈ° λλ¬Έμ true
(3, "apple") < (3, "bird") // 3μ κ°μμ ν¨μ€ aκ° bλ³΄λ€ μκΈ° λλ¬Έμ true
(4, "dog") == (4, "dog") // true
- ννμμ λΉκ΅ μ°μ°μλ₯Ό μ¬μ©νλ©΄ κ°μ΄ λ€λ₯Ό λκΉμ§ μΌμͺ½μμ μ€λ₯Έμͺ½μΌλ‘ νλ²μ νλμ© λΉκ΅νλ€.
- 7κ° λ―Έλ§μ μμλ₯Ό κ°μ§κ³ μλ ννμ λν΄ νν λΉκ΅ μ°μ°μλ₯Ό μ¬μ©ν μ μλ€.
Nil-κ²°ν© μ°μ°μ (Nil-Coalescing Operator)
// μΌνμ°μ°μ μ¬μ©
a != nil ? a! : b
// Nil-κ²°ν© μ°μ°μ μ¬μ©
a ?? b
- a ?? b
- a μ κ°μ΄ μμΌλ©΄ a λ₯Ό νκ±°λ a κ° nil μ΄λ©΄ κΈ°λ³Έκ° b λ₯Ό λ°ν
λ Όλ¦¬μ μ°μ°μ κ²°ν© (Combining Logical Operators)
// enteredDoorCode && passedRetinaScan κ° trueκ±°λ
// hasDoorKeyκ° trueκ±°λ
// knowsOverridePasswordκ° trueλ©΄ true
if enteredDoorCode && passedRetinaScan || hasDoorKey || knowsOverridePassword {
print("Welcome!")
} else {
print("ACCESS DENIED")
}
- λ³΅ν© ννμμ μ½κΈ° μ½κ² νκΈ°μν΄ μκ΄νΈλ₯Ό ν¬ν¨νμ
'Swift Language Guide' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Swift Language Guide] ν¨μ(Functions) (0) | 2023.05.24 |
---|---|
[Swift Language Guide] μ μ΄νλ¦(Control Flow) (0) | 2023.05.24 |
[Swift Language Guide] μ½λ μ νμ (Collection Types) (0) | 2023.05.24 |
[Swift Language Guide] λ¬Έμμ΄κ³Ό λ¬Έμ (Strings and Characters) (2) | 2023.05.16 |
[Swift Language Guide] κΈ°λ³Έ (The Basics) (0) | 2023.05.16 |