HealthKit Quick Start | Ray Wenderlich Videos

HealthKit provides a nice set of API to interact with the heath data store on your iPhone - reading various types of data, writing health data you collect from your user, and even running statistics on that data to present summary information on screen.

This is a companion discussion topic for the original entry at

After making the changes to add biologicalSex, ProfileViewController does not display, and I receive this error (at 4:33 in video):

HealthKitQuickStart[40247:2807229] Presenting view controllers on detached view controllers is discouraged
<HealthKitQuickStart.ProfileViewController: 0x7fa968c25d90>.

However, I tried it on my iPhone 7 Plus and it worked it worked fine; so it only seems to happen in the simulator. I get this popup on the simulator: The operation couldn’t be completed. (Foundation._Generic ObjCError error 0.)

Investigating this difference further, I discovered that the health data for my simulator was not there (which I had set previously). After entering my name, birthdate, sex, weight, height, and blood type, then everything was good. I’m thinking that my Health app was replaced when upgraded to Xcode 9.3 with Swift 4.1 for iOS 11.3 and all my Health data was wiped out.

Earlier I had entered sample health data such as my blood glucose readings, food (carb nutrition), insulin (basal & bolus), and activity (steps & minutes). Now I have to do all that over again (and each time I upgrade, I guess). I need to figure out how to export and import my health data to use the simulator, or else I’ll just have to only use my real iPhone.

Thanks for pointing that out! Yes, the simulator does indeed need data in the Health App for things to work right.

And I think the “Presenting view controllers…” message is more of a warning than an error, but it is something to avoid! I’ll see if I can track down where that is happening.

@hococoder - thank you for sharing this tutorial, it’s straightforward, compact and to the point. It’s gotten me up to speed on HealthKit in no time.

@gsharm1 Really glad it helped! :]