David Seek David Seek - 1 year ago 49
Swift Question

Swift / MotionKit.framework / how to update label

I'm trying to exploit motion data. I've created a test app using the MotionKit Framework.

prints the
variables correctly to the console in an one second interval. But my testLabel will not be updated once.

import UIKit
import MotionKit

class ViewController: UIViewController {

@IBOutlet weak var testLabel: UILabel!

let motionKit = MotionKit()

override func viewDidLoad() {

motionKit.getAccelerometerValues(1.0) { (x, y, z) -> () in
let testString = String(x)
self.testLabel.text = testString

override func didReceiveMemoryWarning() {

What am I missing? Help is very appreciated.

Answer Source

Just wrap your textfield text code in dispatch_async

dispatch_async(dispatch_get_main_queue(), ^{ 
      self.testLabel.text = testString