0

I use swift 3 & xcode8

My code is below

[A]

DispatchQueue(label: "background").async {
            autoreleasepool {

             *DB UPDATE CODE HERE  
            }

            OperationQueue.main.addOperation {
                self.uiUpdate() <-- data query & UI update code   
                self.ResultTable.reloadData() <-- tableview reload 
            }

        } 

[B]

 DispatchQueue(label: "background").async {
        autoreleasepool {

         *DB UPDATE CODE HERE  
        }

        DispatchQueue.main.async {
            self.uiUpdate() <-- [C] some data query & UI update code   
            self.ResultTable.reloadData() <-- [D]tableview reload 
        }

    } 

[A] code is works very well.

but [B] is something wrong

if i execute [B] 5 times

C is works good but sometimes UI is not updated

I heard that OperationQueue.main.addOperation and DispatchQueue.main.async

is same but works differently

I dont understand ,,Diffrence A and B

ttoggaiman
  • 71
  • 2
  • 6

0 Answers0