[iOS] App Development

Sets

ddgoori 2021. 3. 8. 20:58

 

 

dSets Don't store duplicate value

Sets aren't ordered

Dictionary와 뭐가 다른가?

 

Duplicate Value를 넣어도 Swift가 무시함

constant로 선언하면 아무 요소도 삽입할 수 없음 let someSet: Set<Int>

 

remove도 쓸수 있고

실행할 때마다 순서 달라짐

re

intersection

symmetricDifference 를 통해서 

교집합 / 다른 부분 / 유니언 모두 구할 수 있음

 

someSet은 바뀌고

anotherSet은 지나가는건 안바뀜

 

Discussion

If the set already contains one or more elements that are also in other, the existing members are kept. If other contains multiple instances of equivalent elements, only the first instance is kept.

 

 

안겹치는 첫번째 set와 두번째set의 차이만 첫번째 set에 더해줌

var attendees: Set = ["Alicia", "Bethany", "Diana"]
let visitors = ["Diana", "Marcia", "Nathaniel"]
attendees.formUnion(visitors)
print(attendees)
// Prints "["Diana", "Nathaniel", "Bethany", "Alicia", "Marcia"]"