             if let cell = cell as? SubmitWorkoutTableViewCell {
                 cell.switchChangedCallback = { isOn in
                     self.resultWorkoutData.totalDistance = isOn ? self.workoutData.totalDistance : nil
+                    self.defaults.setBool(isOn, forKey: self.kSwitchPrefTotalDistance)
+                }
+                if let switchState = defaults.valueForKey(self.kSwitchPrefTotalDistance) as? Bool {
+                    cell.sendDataSwitch.on = switchState
                 }
             }
         case 4:

            if let cell = cell as? SubmitWorkoutTableViewCell {
                cell.switchChangedCallback = { isOn in
                    self.resultWorkoutData.totalCalories = isOn ? self.workoutData.totalCalories : nil
                }
            }
        case 3:


class SubmitWorkoutViewController: UITableViewController, UIPickerViewDelegate, UIPickerViewDataSource {
    
    let kSwitchPrefTotalCalories = "kSwitchPrefTotalCalories"
    let kSwitchPrefTotalDistance = "kSwitchPrefTotalDistance"
    let kSwitchPrefAverageHeartRate = "kSwitchPrefAverageHeartRate"
    
    let defaults = NSUserDefaults.standardUserDefaults()
    
    var resultWorkoutData: (type: String?, startTime: NSDate?, totalDistance: Double?, duration: Double?, averageHeartRate: Int?, totalCalories: Double?, notes: String?)
    var workoutData: (type: String?, startTime: NSDate?, totalDistance: Double?, duration: Double?, averageHeartRate: Int?, totalCalories: Double?, notes: String?) {
        didSet {
            self.resultWorkoutData = self.workoutData
            
            // Check defaults for switches
            if let switchPrefTotalCalories = defaults.valueForKey(kSwitchPrefTotalCalories) as? Bool where !switchPrefTotalCalories {
                self.resultWorkoutData.totalCalories = nil
            }
            if let switchPrefTotalDistance = defaults.valueForKey(kSwitchPrefTotalDistance) as? Bool where !switchPrefTotalDistance {
                self.resultWorkoutData.totalDistance = nil
            }
            if let switchPrefAverageHeartRate = defaults.valueForKey(kSwitchPrefAverageHeartRate) as? Bool where !switchPrefAverageHeartRate {
                self.resultWorkoutData.averageHeartRate = nil
            }
        }
    }
    var pickerSelection:Int = 0
    
    var useMetric = false

    override func viewDidLoad() {
