[Swift] Collection Type - Set
Set
Set은 순서가 존재하지 않고, 멤버가 유일한 것을 보장하는 데이터 컬렉션 타입이다.
원소의 삽입, 삭제, 갯수의 메소드는 Array와 동일하다.
하지만 Set에서는 순서 개념이 없기 때문에 index를 통해 접근하는 방식은 불가능하다.
var birds : Set<Character> = ["🦢","🐥","🕊"]
// method
birds.insert("🦜")
print(birds)
birds.remove("🐥")
print(birds)
birds.contains("🕊")
// property
birds.isEmpty
birds.count
var flyingBirds : Set<Character> = ["🕊","🦜","🦅"]
// 두 set을 합쳐(합집합) 새로운 Set을 만듦
birds.union(flyingBirds)
// 두 set을 빼서(차집합) 새로운 Set을 만듦
birds.subtract(flyingBirds)
var digitSet : Set<Int> = [1,2,3,4,5,5,5,5,6]
var integerSet : Set<Int> = [4,5,6,1,2,8,9,0]
// 두 set 중 공통되는 집합으로(교집합) 새로운 Set을 만듦
digitSet.intersection(integerSet)
시험기간이라 오늘은 여기까지 ,, ㅠㅠ
Author And Source
이 문제에 관하여([Swift] Collection Type - Set), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@mindyeoi/Swift-Collection-Type-Set저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)