     
     }
     
+    func loadWeightArray() {
+        for (var i = defaultUserWeight; i <= maxUserWeight; i++)
+        {
+            kgArray.append(String(i));
+        }
+    }
+    
+    func selectUserWeight() {
+        let past : NSDate = NSDate.distantPast() as NSDate
+        let now = NSDate()
+        let mostRecentPredicate = HKQuery.predicateForSamplesWithStartDate(past, endDate: now, options: HKQueryOptions.None)
+        let sortDescriptor = NSSortDescriptor(key: HKSampleSortIdentifierStartDate, ascending: false);
+        let idWeight = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMass)
+        let sampleQuery = HKSampleQuery(sampleType: idWeight, predicate: mostRecentPredicate, limit: 0, sortDescriptors: [sortDescriptor], resultsHandler:
+            {(_,results,_) -> Void in
+                
+                if (results != nil) {
+                    let sample = results.first as HKQuantitySample
+                    let quantity = sample.quantity.doubleValueForUnit(HKUnit.gramUnitWithMetricPrefix(.Kilo))
+                    
+                    dispatch_async(dispatch_get_main_queue(), {
+                        self.userWeight = Int(quantity)
+                        self.weightPicker.selectRow(self.selectedRowInComponent(0), inComponent: 0, animated: false)
+                        
+                    })
+                }
+        })
+        
+        healthStore.executeQuery(sampleQuery)
+    }
 }
 

  
    var progress: Int = 0
    
    var kgArray = ["81","82","83","84","85"]
    
    var greenColor = UIColor(red: CGFloat(84.0/255.0), green: CGFloat(174.0/255.0), blue: CGFloat(58.0/255.0), alpha: CGFloat(1.0))
  
    var healthStore : HKHealthStore = HKHealthStore()
  
    var stepCounter : StepCounter?
  
    @IBOutlet weak var weightPicker: UIPickerView!
  

    
    @IBOutlet weak var lblSteps: UILabel!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.loadWeightArray()
        self.selectUserWeight()
        self.stepCounter = StepCounter(healthStore: healthStore, delegate: self);
        
    }
  
    override func viewDidAppear(animated: Bool) {
