dSets Don't store duplicate value
Sets aren't ordered
Dictionary와 뭐가 다른가?
Duplicate Value를 넣어도 Swift가 무시함
constant로 선언하면 아무 요소도 삽입할 수 없음 let someSet: Set<Int>
remove도 쓸수 있고
실행할 때마다 순서 달라짐
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"]"
'[iOS] App Development' 카테고리의 다른 글
[iOS] 기본 개념 정리 #1 : struct(mutating), IBAction, IBOutlet, MVC, Optional, Parameter (0) | 2021.10.29 |
---|---|
[Swift/iOS] Functions and Return / Typealias / Compound Type (0) | 2021.03.09 |
[iOS/Swifit] Dictionary 사용법 (0) | 2021.03.08 |
While Loops / For Loops / Iterating Collections / Nested Loops (0) | 2021.03.05 |
[0] Swift Fundamentals : (0) | 2021.02.16 |