SwiftUI / Day 3

Minsang Kang·2024년 2월 14일
0

100 Days of SwiftUI

목록 보기
4/4
post-thumbnail

Complex data types, part 1

https://www.hackingwithswift.com/100/swiftui/3

How to store ordered data in arrays

https://www.youtube.com/watch?v=K1jEskrHcyY

  • '[]'를 사용해서 배열 생성
  • 배열은 같은 타입들만 지닐 수 있음
  • .append()를 사용해서 배열에 추가
  • [0]과 같이 값을 접근할 수 있음
  • 빈배열 생성
var scores = Array<Int>()
var scores = [Int]()
var scores: [Int] = []
  • .count 를 통해 배열 인자수를 알 수 있음
  • .remove(at: ) 함수를 통해 제거할 수 있음
  • .removeAll() 함수를 통해 전체를 제거할 수 있음
  • .contains() 함수를 통해 특정 인자를 포함하는지 확인할 수 있음
  • .sorted() 를 통해 정렬할 수 있음
  • .reversed() 를 통해 역순으로 정렬할 수 있음

How to store and find data in dictionaries

https://www.youtube.com/watch?v=iM2lMBAckKg

  • dictionary는 key, value 형식
  • dictionary는 중복된 key 값을 허용하지 않음, 이전 값이 삭제됨
  • dictionary는 순서를 지닐 수 없음
  • ["key": value] 식으로 dictionary를 생성할 수 있음
  • dict["key"] 값은 optional 값
  • dict["key", default: "Unknown"] 값은 optional이 아닌 값
  • dict["key"] = value 식으로 값 추가 가능
  • 빈 딕셔너리 생성
var heights = [String: Int]()
var heights: [String: Int] = [:]

How to use sets for fast data lookup

https://www.youtube.com/watch?v=9GjGRqK8LSw

  • set은 중복된 값을 지닐 수 없음
  • set은 순서를 지닐 수 없음, 단 최적화된 순서로 데이터를 저장
  • 이를 통해 매우 빠르게 찾을 수 있음 (검색을 위한 최적화)
  • .insert() 함수로 추가할 수 있음
  • 빈 set 생성
var people = Set<String>()

How to create and use enums

https://www.youtube.com/watch?v=bwqbf-1_7gE

  • enum: 제한된 case를 통해 실수를 제한
  • . 를 통해 case를 선택할 수 있음
  • 최적화되어 사용되기에 enum 없이 값을 지정하는 것 보다 빠름

사용용도

  • Directions (north, south, etc)
  • Errors
  • Genres of movies
  • Suits in a deck of cards
  • Months of the year
  • Days of the week
profile
 iOS Developer

0개의 댓글