본 블로그는 개인적인 공부 및 저장의 용도 작성됐습니다.
//선언법
//Main Operation Queue 선언
let mainOper = OperationQueue.main
//Custom Operation Queue 선언
let custumOper = OperationQueue()
custumOper.name = "Custom Queue"
custumOper.qualityOfService = .default
// Add Block Operation
// 1. 블록 선언 후 추가
//instance of operation subclass
let operation = BlockOperation {
// something to do
}
//block: () -> void
custumOper.addOperation(operation)
//2. 선언과 동시에 추가
//add a block : { code }
custumOper.addOperation {
// something to do
}
//multiple tasks
var opers = [Operation]()
opers.append(operation)
opers.append(operation)
//ops: [Operation], waitUntilFinished: Bool
custumOper.addOperations(opers, waitUntilFinished: false)
// 3 operations may execute at once
custumOper.maxConcurrentOperationCount = 3
//일시정지
custumOper.isSuspended = true
//다시시작
custumOper.isSuspended = false
참조
https://riptutorial.com/swift/example/13293/running-tasks-in-an-operationqueue
https://stackoverflow.com/questions/10373331/nsoperation-vs-grand-central-dispatch/40064466#40064466