DispatchQueue

Tabber·2021년 7월 5일
0

Apple Document

목록 보기
5/12

An object that manages the execution of tasks serially or concurrently on your app's main thread or on a background thread.
앱의 기본 스레드 또는 백그라운드 스레드 상에서 직렬 또는 동시에 태스크 실행을 관리하는 개체입니다.

DispatchQueue 는 작업항목의 실행을 관리하는 클래스이다.
주로 iOS 에서는 서버에서 데이터를 내려받는다든지 이미지, 동영상 등 멀티미디어 처리와 같이 CPU사용량이 많은 처리를 별도의 스레드에서 처리한 뒤 메인 스레드로 결과를 전달하여 화면에 표시한다.

Overview

Dispatch queues are FIFO queues to which your application can submit tasks in the form of block objects. Dispatch queues execute tasks either serially or concurrently. Work submitted to dispatch queues executes on a pool of threads managed by the system. Except for the dispatch queue representing your app's main thread, the system makes no guarantees about which thread it uses to execute a task.
디스패치 대기열은 애플리케이션이 블록 개체 형식으로 작업을 제출할 수 있는 FIFO 대기열입니다. 디스패치 대기열은 태스크를 직렬 또는 동시에 실행합니다. 대기열을 발송하기 위해 제출된 작업은 시스템에서 관리하는 스레드 풀에서 실행됩니다. 앱의 메인 스레드를 나타내는 디스패치 큐를 제외하고 시스템은 태스크를 실행하기 위해 어떤 스레드를 사용하는지 보증하지 않습니다.

큐 형식으로 먼저 들어갔던게 제일 먼저나오는 대기열이다.


You schedule work items synchronously or asynchronously. When you schedule a work item synchronously, your code waits until that item finishes execution. When you schedule a work item asynchronously, your code continues executing while the work item runs elsewhere.
작업 항목을 동기식 또는 비동기식으로 예약합니다. 작업 항목을 동시에 예약하면 코드가 해당 항목의 실행을 마칠 때까지 기다립니다. 작업 항목을 비동기식으로 예약하면 작업 항목이 다른 곳에서 실행되는 동안 코드가 계속 실행됩니다.

큐를 동기식과 비동기식으로 구현할 수 있다보다.

main

The dispatch queue associated with the main thread of the current process.
현재 프로세스의 기본 스레드와 연결된 디스패치 대기열입니다.

The system automatically creates the main queue and associates it with your application’s main thread. Your app uses one (and only one) of the following three approaches to execute blocks submitted to the main queue:

시스템이 자동으로 기본 대기열을 생성하여 응용 프로그램의 기본 스레드와 연결합니다. 앱은 다음 세 가지 접근 방식 중 한 가지만 사용하여 메인 큐에 제출된 블록을 실행합니다.

  • Calling dispatchMain()
    dispatchMain() 호출
  • Starting your app with a call to UIApplicationMain(::::) (iOS) or NSApplicationMain(::) (macOS)
    UIAplicationMain(iOS) 또는 NSApplicationMain(::_:)(macOS) 호출로 앱 시작
  • Using a CFRunLoop on the main thread
    메인 스레드에서 CFRunLoop 사용

func asyncAfter

// asyncAfter(deadline:execute:) : 지정된 시간에 실행하기 위해 클로저를 
// DispatchQueue에 추가 > 그리고 지정된 시간이 지나면 바로 실행
func asyncAfter(deadline: DispatchTime, execute: DispatchWorkItem)
profile
iOS 정복중인 Tabber 입니다.

0개의 댓글