- Array: ์์๊ฐ ์๋ ๋ฆฌ์คํธ ์ปฌ๋ ์
var integers: Array<Int> = Array<Int>()
integers.append(1)
integers.append(100)
//integers.append(101.1) // ์ค๋ฅ
integers.contains(100) // true
integers.remove(at:0) // 0๋ฒ ์ธ๋ฑ์ค์ ๊ฐ ์ญ์
integers.removeLast()
integers.removeAll()
integers.count
// Array<Double>์ [Double]์ ๋์ผํ ํํ
var doubles: Array<Double> = [Double]()
var strings: [String] = [String]()
var characters: [Character] = []
// let์ ์ฌ์ฉํ์ฌ ๋ถ๋ณ Array ์์ฑ
let immutableArray = [1,2,3]
- Dictionary: ํค์ ๊ฐ์ ์์ผ๋ก ์ด๋ฃจ์ด์ง ์ปฌ๋ ์
// Key๊ฐ String ํ์
์ด๊ณ Value๊ฐ Any์ธ ๋น Dictionary ์์ฑ
var anyDictionary: Dictionary<String,Any> = [String:Any]()
// Key์ ํด๋น๋๋ ๊ฐ ํ ๋น
anyDictionary["someKey"] = "someValue"
anyDictionary.removeValue(forKey: "someKey")
// empty Dictionary ์์ฑ
let emptyDictionary: [String:String] = [:]
// Dictionary ์ด๊ธฐํ ์์ฑ
let initalizedDictionary: [String:String] = ["name":"yujin","gender":"female"]
let someValue: String = initalizedDictionary["name"] // yujin
- Set: ์์๊ฐ ์๊ณ , ๋ฉค๋ฒ๊ฐ ์ ์ผํ ์ปฌ๋ ์
var integerSet: Set<Int> = Set<Int>()
integerSet.insert(1)
integerSet.insert(100)
integerSet.insert(99)
integerSet.insert(99)
integerSet // {100,99,1}
integerSet.contains(1) //true
integerSet.remove(100)
integerSet.removeFirst()
integerSet.count
let setA: Set<Int> = [1,2,3,4,5]
let setB: Set<Int> = [3,4,5,6,7]
let union: Set<Int> = setA.union(setB) //ํฉ์งํฉ {4, 3, 6, 1, 5, 7, 2}
let sortedUnion: [Int] = union.sorted() // [1, 2, 3, 4, 5, 6, 7]
let intersection: Set<Int> = setA.intersection(setB) // ๊ต์งํฉ
let subtracting: Set<Int> = setA.subtracting(setB) // ์ฐจ์งํฉ
'๐ iOS > Swift' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Swift] ๋งค๊ฐ๋ณ์/์ ๋ฌ์ธ์ ๋ ์ด๋ธ/๊ฐ๋ณ ๋งค๊ฐ๋ณ์ (0) | 2021.03.15 |
---|---|
[Swift] ๊ธฐ๋ณธ ํจ์ function (0) | 2021.03.10 |
[Swift] Any, AnyObject, nil (0) | 2021.03.10 |
[Swift] Struct์ Class (0) | 2021.03.10 |
[ Swift ] ์ฌ๋ฌ ์ค์ ๋ฌธ์์ด์ ๋ง๋๋ ๋ฐฉ๋ฒ (0) | 2021.02.01 |