Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use dispatch queue for high Priority in background in Swift 3.1

    let dict_one=result[i]

    let product:AllProducts=AllProducts()

    product.applications=dict_one.objectForKey("applications") as? String

    product.desc=dict_one.objectForKey("description") as? String

    product.familyId=String(dict_one.objectForKey("familyId") as! Int)

    if dict_one.objectForKey("imageName") as? String  != nil
    {
        product.imageName=dict_one.objectForKey("imageName") as? String

        let url:String =  AppConstant.GetAllImages + (dict_one.objectForKey("imageName") as? String)!

        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0))
        {
         let imagePath=self.fileInDocumentsDirectory((dict_one.objectForKey("imageName") as? String)!)
         self.saveImage(url, image_name1: (dict_one.objectForKey("imageName") as? String)!,path: imagePath)
        }
    }
    else
    {
        product.imageName=""
    }

I need to use dispatch queue for high Priority in background in swift 3.1 can you help to find out the solution?

like image 389
Deevakar verma Avatar asked Jan 20 '26 01:01

Deevakar verma


1 Answers

Here you go:

DispatchQueue.global(qos: .userInitiated).async {
     //Your code goes here

     //Coming back to the main queue to update the UI
     DispatchQueue.main.async {
         //Update your ui (reloading tableView, Label update, etc. here)
     }
}

Hope this helps.

like image 179
Md. Ibrahim Hassan Avatar answered Jan 22 '26 13:01

Md. Ibrahim Hassan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!