-
Tuples - TuplesiOS/π Swift 2020. 10. 25. 10:30
" νλμ μμ νΉμ λ³μμ μ¬λ¬ κ°μ κ°μ μ μ₯ν μ μμκΉ?"
κΈ°μ‘΄μ Int, String κ³Ό κ°μ νμ μ νλμ μμ νΉμ λ³μμ νλμ κ°μ μ μ₯ν μ μμμ΅λλ€.
μ΄λ° νμ μ Scalar Type μ΄λΌκ³ ν©λλ€.
Tuples μ Compound Type μ λλ€. μ¬λ¬ κ°μ κ°μ μ μ₯ ν μ μμ΅λλ€.
let myTuples = (1, "This", "is", "Awesome", 111)
Tuples μ κ΄νΈλ₯Ό μ΄μ©νμ¬ ννν©λλ€.
κ΄νΈ μμ νλ νλμ μμλ Member λΌκ³ λΆλ¦ λλ€.
μμ myTuples λ ( Int, String, String, String, Int ) νμ κ°μ΅λλ€.
μ μΈλ Tuplesμ Members λ μΆκ° λ° μ κ±°κ° λΆκ°λ₯ ν©λλ€.
Tupels μ Members λ . (dot) μ μ΄μ©νμ¬ μ κ·Όν©λλ€.
Tuples λ κ° νμ μ λλ€.
λ°λΌμ λ€λ₯Έ Tuples μ λμ μ κ°μ΄ 볡μ¬λμ΄ μ μ₯λ©λλ€.
Mutability
μμ Tuples λ Immutable ν©λλ€. ( λΆλ³ νν )
λ³μ Tuples λ Mutable ν©λλ€. ( κ°λ³ νν )
λμ μ°¨μ΄λ Members κ°μ λ³κ²½ κ°λ₯ μ¬λΆ μ λλ€.
let immutableTupels = ("can't", "change", "members") immutbaleTupels.0 = "can" // compile error var mutableTuples = ("i", "can" , "lol") mutableTuples.2 = "tho" // ("i, "can", "tho")
Named Tuples VS. Unnamed Tuples
μμμ 보μ¬λλ¦° μ½λλ λͺ¨λ Unnamed Tuples μ λλ€.
Tuples μ Members μ κ·Ό λ°©λ²μμ μ§κ΄μ μ΄μ§ μμ, κ°λ μ±μ΄ λ¨μ΄μ§λλ€.
μλλ Named Tuples μ Unnamed Tuples μ Members μ κ·Ό λ°©μμ μ°¨μ΄λ₯Ό 보μ¬μ€λλ€.
/* Unnamed Tuples */ let guest1 = ("David", 19, "U.S") guest1.0 // "David" guest1.1 // 19 guest1.2 // "U.S" /* Named Tuples */ let guest2 = (name: "Laura", age: 21, nationality: "France") guest2.name // "Laura" guest2.age // 21 guest2.nationality // "France"
Named Tupels μ Members μ κ·Ό λ°©μμ΄ λ μ§κ΄μ μΌλ‘ 보μ λλ€.
Swift μμλ . (dot) μ μ΄μ©ν λ¬Έλ²μ Explicit Member Expression μ΄λΌκ³ λΆλ¦ λλ€.
λ.
'iOS > π Swift' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
Type Inference - Data Types (0) 2020.11.03 3 features of First Class Citizen - Function (0) 2020.11.02 Swift) Raw Value - Enumeration (0) 2020.10.24 Optional Unwrapping - Optionals (0) 2020.10.09 Optionals - Optionals (0) 2020.10.09