ios - Why is "print into console" much faster than ".text into label " -


i´m trying display cadence , pace data of cmpedometer. when run application phone attached, writes output of data through print("...") function console, takes multiple turns until displays data in uilabel. how can data fast possible can use them?

best, zack

import uikit import coremotion  class viewcontroller: uiviewcontroller {     let pedometer = cmpedometer()     @iboutlet weak var pacelabel: uilabel!     @iboutlet weak var cadencelabel: uilabel!      override func viewdidload() {         super.viewdidload()          guard cmpedometer.iscadenceavailable() && cmpedometer.ispaceavailable() else{             print("pace , cadence data not available")             return         }                  let oneweekago = nsdate(timeintervalsincenow: -(7 * 24 * 60 * 60))         pedometer.startupdates(from: oneweekago date) {data, error in             guard let pdata = data , error == nil else{                 return             }             //the current pace of user, measured in seconds per meter. (1 step = 83cm?)             if let pace = pdata.currentpace{                 print("pace = \(pace)")                 self.pacelabel.text = "pace = \(round(double(pace))*10/10)"             }             //the rate @ steps taken, measured in steps per second.             if let cadence = pdata.currentcadence{                 self.cadencelabel.text = "cadence = \(cadence))"                 print("cadence = \(cadence)")             }         }// -----------------oneweekago             }// -----------------viewdidload      override func didreceivememorywarning() {         super.didreceivememorywarning()     } }//-------------------- uiviewcontroller 

the update block called on background thread , need update ui on main thread. wrap ui update calls in dispatch main thread:

dispatch.main.async {     //the current pace of user, measured in seconds per meter. (1 step = 83cm?)     if let pace = pdata.currentpace{         print("pace = \(pace)")         self.pacelabel.text = "pace = \(round(double(pace))*10/10)"     }      //the rate @ steps taken, measured in steps per second.     if let cadence = pdata.currentcadence{         self.cadencelabel.text = "cadence = \(cadence))"             print("cadence = \(cadence)")         }     } } 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -