HealthKit for iOS8: Part 7

4. CoreData for other non-health stats You made it to the end!  Ok, so we are basically going to be adding another store to our app and reading and writing data to THAT store as well. First let’s add a new tab and make it a UITableViewController as well.  It will have dynamically populated cells. Now embed it!   Your final storyboard should look like this:   Add a new Swift class called Swimming Data and set that new UITableViewController scene to its class.  Make that class file look like this: import Foundation import UIKit class SwimmingData: UITableViewController { } Now we must add CoreData.  To do this we need to… Read More

Continue Reading

HealthKit for iOS8: Part 6

Here is the start of our WorkOut view controller: import Foundation import UIKit import HealthKit class WorkoutViewController: UITableViewController, UITextFieldDelegate { @IBOutlet var numberOfLapsTextField: UITextField! @IBOutlet var metersPerLapTextField: UITextField! @IBOutlet var workoutDurationTextField: UITextField! @IBOutlet var paceTextField: UITextField! var numberOfLapsValue: NSString? var metersPerLapValue: NSString? var workoutDurationValue: NSString? var userWeight: Double? var  healthStore:HKHealthStore? } We import what we need, we subclass UITableViewController and add the Text Field delegate protocol.  Here I have created 4 labels for: numberOfLaps metersPerLap workoutDuration pace These labels have an underlying variable for each.  The reason the first 3 are strings is because these are not health kit data per se.  These will be stored in CoreData.  However they… Read More

Continue Reading

HealthKit for iOS8: Part 5

Jumping right in, our Energy view controller class starts out like this: import Foundation import UIKit import HealthKit class EnergyViewController: UITableViewController { var energyFormatter: NSEnergyFormatter { var energyFormatter: NSEnergyFormatter? var onceToken: dispatch_once_t = 0 dispatch_once(&onceToken, { energyFormatter = NSEnergyFormatter() energyFormatter?.unitStyle = NSFormattingUnitStyle.Long energyFormatter?.forFoodEnergyUse = true energyFormatter?.numberFormatter.maximumFractionDigits = 2 }) return energyFormatter! } // No required initWithCoder pasted in… var  healthStore:HKHealthStore? @IBOutlet weak var activeEnergyBurnedValueLabel: UILabel? @IBOutlet weak var restingEnergyBurnedValueLabel: UILabel? @IBOutlet weak var consumedEnergyValueLabel: UILabel? @IBOutlet weak var netEnergyValueLabel: UILabel? var activeEnergyBurned: Double = 0 var restingEnergyBurned: Double = 0 var consumedEnergy: Double = 0 var netEnergy: Double = 0 } We take care of our imports, subclass UITableViewController, create… Read More

Continue Reading

HealthKit for iOS8: Part 3

Great!  Now let’s move on to the Journal View Controller.  It’ll be a good relax! 🙂 Ok we start out importing the frameworks we need: import UIKit import HealthKit Ok now let’s declare our class properties: class JournalViewController: UITableViewController {     let JournalViewControllerTableViewCellReuseIdentifier: NSString = “Cell”     var foodItems: NSMutableArray?     var energyFormatter: NSEnergyFormatter {         var energyFormatter: NSEnergyFormatter?         var onceToken: dispatch_once_t = 0         dispatch_once(&onceToken, {             energyFormatter = NSEnergyFormatter()             energyFormatter?.unitStyle = NSFormattingUnitStyle.Long             energyFormatter?.forFoodEnergyUse = true      … Read More

Continue Reading
iOS 8 HealthKit Santiapps Marcio Valenzuela

HealthKit for iOS8: Part 4

Ok so the Journal view controller was quite simple.  Let’s take another quick break by looking at an even simpler view controller, the FoodPicker: import Foundation import UIKit import HealthKit class FoodPickerViewController: UITableViewController { var selectedFoodItem: FoodItem? let FoodPickerViewControllerTableViewCellIdentifier:NSString = “cell” let FoodPickerViewControllerUnwindSegueIdentifier:NSString = “FoodPickerViewControllerUnwindSegueIdentifier” var foodItems: NSArray = NSArray() var energyFormatter: NSEnergyFormatter { var energyFormatter: NSEnergyFormatter? var onceToken: dispatch_once_t = 0 dispatch_once(&onceToken, { energyFormatter = NSEnergyFormatter() energyFormatter?.unitStyle = NSFormattingUnitStyle.Long energyFormatter?.forFoodEnergyUse = true energyFormatter?.numberFormatter.maximumFractionDigits = 2 }) return energyFormatter! } var  healthStore:HKHealthStore? } Here we are looking at imports, subclassing UITableViewController and property declarations. Our first property is selectedFoodItem, which will be set to whatever value the user selects from… Read More

Continue Reading