How to create dispatch queue in Swift 3

前端 未结 15 2091
余生分开走
余生分开走 2020-11-22 16:35

In Swift 2, I was able to create queue with the following code:

let concurrentQueue = dispatch_queue_create(\"com.swift3.imageQueue\", DISPATCH_QUEUE_CONCURR         


        
15条回答
  •  一整个雨季
    2020-11-22 17:27

    Creating a concurrent queue

    let concurrentQueue = DispatchQueue(label: "queuename", attributes: .concurrent)
    concurrentQueue.sync {
    
    }  
    

    Create a serial queue

    let serialQueue = DispatchQueue(label: "queuename")
    serialQueue.sync { 
    
    }
    

    Get main queue asynchronously

    DispatchQueue.main.async {
    
    }
    

    Get main queue synchronously

    DispatchQueue.main.sync {
    
    }
    

    To get one of the background thread

    DispatchQueue.global(qos: .background).async {
    
    }
    

    Xcode 8.2 beta 2:

    To get one of the background thread

    DispatchQueue.global(qos: .default).async {
    
    }
    
    DispatchQueue.global().async {
        // qos' default value is ´DispatchQoS.QoSClass.default`
    }
    

    If you want to learn about using these queues .See this answer

提交回复
热议问题