모바일앱/Swift

Collection - Set

GeekCode 2021. 10. 10. 16:41
반응형

Collection -  Set

기본 개념

 

다양한 종류가능

 

- 순서가 없다!!

- 중복이 없는 유니크한 아이템을 관리할때 사용한다.

 

import UIKit

var someArray: Array<Int> = [1, 2, 3,1] //[1, 2, 3, 1]
var someSet: Set<Int> = [1,2,3,1,2] //{3, 1, 2}


// collection의 공통 property
someSet.isEmpty
someSet.count
someSet.contains(1) //true

someSet.insert(5)
someSet //{3, 1, 2, 5}

someSet.remove(1)
someSet //{2, 5, 3}

 

반응형