Swift, Label not refreshing while in callback function

I want to change/reload my label on activity indicator while i am running on the loop.

But it is not reloading because of “self.netUtil.callWebservice(urlStr) {(data)” i presume.



My code is below

—————————————



self.showActivityIndicator(self.view,message: "Please wait..synchronization is in progress")

//Logic synchronization all Web Service

var urlStr: String = "\(constants.SERVER_URL)"

self.netUtil.callWebservice(urlStr) {(data) -> Void in //I suspect this method to reason why my label is not refreshing

self.beginParsing()

var unitCount = 0

for Prop: Property in self.properties

{

unitCount++

for view in self.view.subviews

{

if view is UILabel

{

view.removeFromSuperview()

}

}

/ refresh label code start here */

var totCount = self.properties.count

var message = "Synchronization \(unitCount)/\(totCount) buildings completed"


dispatch_async(dispatch_get_main_queue(), {


self.lblProcess.text = message

self.lblProcess.setNeedsDisplay()

self.container.addSubview(self.lblProcess)

})

/ refresh label code End here */



//Backup code to be shfted while pushing in web service

self.fileMgr.getSurveyorUnitFiles("", proCode: Prop.proCode as String, isCreateBackup: true)

//back up code ended

self.callUnitsWebservice(Prop.proCode as String) //another web service cal

}

self.hideActivityIndicator()

}

If i am putting the label out of the loop than it is reloading…

What should i do reload label in the loop so that it changes when each loop gets excited?



Thanks for the help in advance

Why you are removing all the labels from the view before adding lblProcess label? Just update lblProcess label's text if that is all that is changing. You are also removing views on background thread (if callback is not running on main thread).

Hi ,


I have commented my removing view code.

Still it is displaying the same.


Code below

-----------------------



for Prop: Property in self.properties

{


/ refresh label code start here */

dispatch_async(dispatch_get_main_queue(), {

/

self.unitCount++

println("unitCount \( self.unitCount)")

var totCount = self.properties.count

var message = "Synchronization \(self.unitCount)/\(totCount) buildings completed"

self.lblProcess.text = message

/

})

/ refresh label code End here */

/

self.fileMgr.getSurveyorUnitFiles("", proCode: Prop.proCode as String, isCreateBackup: true)

/

self.callUnitsWebservice(Prop.proCode as String,unitCount:unitCount) /

}

Is the self.netUtil.callWebservice(urlStr, {...}) call actually running that closure in the background in another thread, or do you need to do it yourself?


self.showActivityIndicator(self.view,message: "Please wait..synchronization is in progress")

//Logic synchronization all Web Service
var urlStr: String = "\(constants.SERVER_URL)"

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {

    self.netUtil.callWebservice(urlStr) {(data) -> Void in

        self.beginParsing()
        var unitCount = 0
    
        for Prop: Property in self.properties
        {
            /* refresh label code start here */
            var totCount = self.properties.count
            var message = "Synchronization \(unitCount)/\(totCount) buildings completed"
        
            dispatch_async(dispatch_get_main_queue()) {
                self.lblProcess.text = message
                self.lblProcess.setNeedsDisplay()
            }
            /* refresh label code End here */
        
        
            //Backup code to be shfted while pushing in web service
            self.fileMgr.getSurveyorUnitFiles("", proCode: Prop.proCode as String, isCreateBackup: true)
        
            //back up code ended
            self.callUnitsWebservice(Prop.proCode as String)  //another web service call
        
            unitCount++
        }
    
        dispatch_async(dispatch_get_main_queue()) {self.hideActivityIndicator()}
    }
}
Swift, Label not refreshing while in callback function
 
 
Q