λ°μν
π λͺ©μ°¨
- array
- dictionary
- set
π array
arrayλ λ°μ΄ν° νμ μ κ°λ€μ μμλλ‘ μ μ₯νλ 리μ€νΈ μ λλ€.
κΈ°λ³Έ μμ±μ
var numbers: Array<Int> = Array<Int>()
// or
// var number: Array<Int> = [1, 2, 3, 4]
// or
// var numbers = [Int]()
// or
// var numbers: [Int] = []
append -> 맨λ€μ λΆμΈλ€ (push κ°μ κΈ°λ₯)
var numbers: Array<Int> = Array<Int>()
numbers.append(1)
numbers.append(2)
numbers.append(3)
// numbers [1, 2, 3, 4]
insert -> μ€κ°μ μμλ₯Ό μ½μ νλ€
numbers.insert(4, at: 2); // 2λ²μΈλ±μ€μ 4λ₯Ό λ£λλ€
// [1, 2, 4, 3]
remove -> μμλ₯Ό μμ νλ€.
numbers.remove(at: 2)
π dictionary
dictionaryλ μμμ μκ΄μμ΄ ν€μ κ° νμμΌλ‘ λ°μ΄ν°λ₯Ό μ μ₯νλ 컬λ μ νμ μ λλ€.
κΈ°λ³Έ μμ±μ
var dic: Dictionary<String, Int> = Dictionary<String, Int>()
// or
var dic: [String: Int] = [:]
μ½μ
var dic: [String: Int] = ["eddie" : 1, "sam" : 2]
dic["eddie"] = 4;
dic["claire"] = 112;
dic // ["sam": 2, "claire": 112, "eddie": 4]
μμ (removeValue)
var dic: [String: Int] = ["eddie" : 1, "sam" : 2]
dic .removeValue(forKey: "eddie")
dic // ["sam": 2]
π set
setμ κ°μ λ°μ΄ν° νμ μ κ°μ μμ μμ΄ μ μ₯νλ 리μ€νΈ μ λλ€.
κΈ°λ³Έ μμ±μ
var set: Set = Set<Int>()
μ½μ (insert)
var set: Set = Set<Int>()
set.insert(10)
set.insert(20)
set.insert(30)
set // {20, 30, 10}
μμ (remove)
var set: Set = Set<Int>([1, 2, 3])
set.remove(1)
set // {2, 3}
λ°μν
'Swift' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
Swift ꡬ쑰체μ ν΄λμ€ (0) | 2021.11.21 |
---|---|
Swift μ΅μ λ (0) | 2021.11.20 |
Swift ν¨μ (0) | 2021.11.20 |
Swift for loop and While (0) | 2021.11.19 |
Swift λ³μ, μμ κ·Έλ¦¬κ³ νμ (0) | 2021.11.19 |