NOW-ON / iOS-Interview-Preparation

iOS 면접 준비
3 stars 0 forks source link

Collection Type의 종류와 특징 #8

Closed Glsme closed 1 year ago

Glsme commented 1 year ago

🗓️ 마감일

2023.01.15

💁 참여자

⚠️ 마지막으로 답변 단 사람이 이슈 close 하고 리드미에 항목 업데이트 해주세요.

Yun-YeoJin commented 1 year ago

Array, Set, Dictionary 세 가지가 있다. var(변수)로 할당하면 변경이 가능하지만, let으로 할당하면 변경이 불가능하다.

  1. Array(배열) : [Element] 형태, .count를 이용해 갯수 확인 가능, .append나 .insert를 통해 원소 추가 가능, for_in loop 순회 가능
  2. Set : Set 형태로 저장되기 위해서는 타입이 hashable(String, Int, Double, Bool)이어야 한다. Set 식으로 선언 가능 -> intersection(교집합), symmetricDifference(차집합), union(합집합), subtracting(여집합)
  3. Dictionary(딕셔너리) : [Key, Value] 형태, [Int, String] 형태로 선언 가능
wodyddml2 commented 1 year ago
Glsme commented 1 year ago

Array

heydoy commented 1 year ago

콜렉션 타입의 종류 및 특징

image

Swift 의 이런 타입들은 모두 Generic Collection 모든 콜렉션 타임은 Iteratable 하다. for-in 반복문으로 순회가 가능

배열(Array)

var intArray: [Int] = [1, 2, 3]
var threeInt = Array(repeating: 0, count: 3)

var addedArray = intArray + threeInt

Swift의 배열은 FoundationNSArray 클래스와 연결됨

세트(Set)

var charSet = Set<Characters>()
var strSet: Set<String> = ["hello", "swift"]

image image

딕셔너리(Dictionary)

var cats: [String: Int] = ["코숏": 3, "아메숏": 2] 
LeeJoobang commented 1 year ago

Collection Type의 종류와 특징 설명