-
[사전캠프 TIL 7일차] GCD (DispatchQueue 종류 & 특성)iOS💖 2025. 2. 13. 15:50
학습 키워드
🗂️ GCD : DispatchQueue 종류 & 특성 🔴
DispatchQueue 종류
: 작업의 특성에 맞게 Queue 선택1. Main Queue
2. Global Queue
3. Custom Queue (private)

DispatchQueue 의 종류 1. Main Queue
- Serial 특성을 가진 Queue
- 하나의 thread 에 분배
- 종류 x (global queue는 6개 가짐)
- Main queue에 들어오는 작업은, Main thread에서 처리됨 🔴
- 작업 종류 예) UI 업데이트 내용
2. Global Queue
- Concurrent 특성을 가진 Queue
- 여러개의 thread 에 분배
- QoS (Quality of Service) 6가지에 따라 우선순위 결정
(높은 순위부터)
- userInteractive
- 사용자와 직접 상호작용하는 작업 (ex. UI 업데이트, 애니메이션 등)
- main thread 에서 처리하면 많은 로드 걸리는 작업,
➡️ userInteractive 처리해, 바로 동작하는 것처럼 보이게 함
- userInitiated
- userInteractive 작업 보다는 조금 더 오래 걸릴 수 있고, 사용자가 이를 어느정도 인식하고 있는 작업
- 클릭 했을 때, 즉각적인 결과가 필요한 작업 (ex. 저장된 문서 열기)
- default
- 일반적인 작업
- utility
- 보통 progress bar 와 함께, 길게 실행되는 작업 (ex. 데이터 다운로드)
- background
- 사용자가 직접적으로 인지 x, 덜 중요한 작업 (ex. 동기화 / 백업)
- unspecified (거의 사용 x)
- QoS 정보가 없음을 나타냄
- userInteractive
- 작업 우선순위에 따른, thread 배치 예시)
- 우선순위가 높을 수록, 더 많은 thread 배치

작업 우선순위에 따른, thread 배치 - +) task 에도 qos 설정 가능!
DispatchQueue.global(qos: .background).async(qos: .utility) { // 🔴 // task }- 작업 보낼 때, 순서 중요하지 않을 때
DispatchQueue.global().async { }- 작업 보낼 때, 작업 중요도 결정할 때
DispatchQueue.global(qos: .userInteractive).async { }3. Custom Queue
- 개발자가 커스텀으로 만든 큐
- default: Serial 속성
➡️ Concurrent 속성으로 설정 가능!- 매개변수 label 값 설정시 ➡️ Serial 특성 가짐
- 매개변수 attributes 값에 .concurrent 설정시 ➡️ Concurrent 특성 가짐
- QoS 설정 가능
(명시적 설정 가능 / 명시적 설정하지 않았다면 OS가 알아서 추론!)
// 🔴 Serial let customSerialQueue = DispatchQueue(label: "network") // 🔴 Concurrent let customConcurrentQueue = DispatchQueue(label: "network", attributes: .concurrent) // 🔴 qos let customConcurrentQueue = DispatchQueue(labal: "network", qos: .background, attributes: .concurrent)회고
(그래서 이거를어떻게 프로젝트에 잘 적용할 것인가 2222)
출처
[iOS] 차근차근 시작하는 GCD — 5
GCD Dispatch Queue의 종류와 특성에 대해 알아봅시다
sujinnaljin.medium.com
[iOS] DispatchQueue와 task의 QoS 가 다를때의 동작 방식
차근차근 시작하는 GCD — 5 번외편
sujinnaljin.medium.com
https://developer.apple.com/documentation/dispatch/dispatchqueue
DispatchQueue | Apple Developer Documentation
An object that manages the execution of tasks serially or concurrently on your app’s main thread or on a background thread.
developer.apple.com
'iOS💖' 카테고리의 다른 글
[사전캠프 TIL 9, 10일차] Combine 딥다이브 🔥 (0) 2025.02.14 [사전캠프 TIL 8일차] Generic (0) 2025.02.13 [사전캠프 TIL 6일차] GCD (Serial vs. Concurrent) (0) 2025.02.12 [사전캠프 TIL 5일차] GCD (+α), Operation (0) 2025.02.07 [사전캠프 TIL 4일차] 비동기 프로그래밍 (with. GCD 💝) (2) 2025.02.06 - Serial 특성을 가진 Queue