Recent Posts

Error Code #3, or ‘The Adventure of Deleting a HealthKit Object’

“An invalid argument was provided to the HealthKit API.”

This dreaded error has a code of #3. It signifies my lack of knowledge about how HealthKit works, as well as how it should work.

Unfortunately, duplicate samples can be added to Health. If the framework relied on indexOf to delete an object with matching properties, only the first occurrence would be deleted. Therefore, Apple doesn’t want to prescribe a deletion method, relying instead on shared identifiers between the exact same instances.

Because of this, instantiating a new HKObject (HKCategorySample in my case) with any properties and passing it to the delete method will throw an error like the one above.

While I was debugging this issue, I thought it was ridiculous that an error message blaming the source code would be used to communicate that a HealthKit object couldn’t be found (“Failed to find some objects for deletion”). However, it turns out that the code looked fine on the surface, while actually assuming the existence of a flaw in HealthKit’s design, by expecting it to figure out which exact object to delete.

My (now obvious) solution was to iterate over the results of an HKSampleQuery and delete the first object that shares properties with the custom object set for deletion by the user. If you just can’t ignore duplicates at runtime and want to avoid unexpected behavior (which, of course, was the whole point of HealthKit not using indexOf), you can keep track of which Nth occurrence to delete with a similar loop.

Sourced from Allan’s Stack Overflow post.

This Blog Turns 2!

I’ve started and quit quite a few different blogs, but none of them were about technology until 2017.

I published this site’s first placeholder post on this day two years ago. Many drafts, hosting platforms, and writing workflows later, I have thirty text files in my “posts” directory.

Fast forward to last month and I’ve added a micro post format to improve the freshness of the home page while encouraging me to write more frequently.

Thanks for reading, and see you in 2020!

The 16-inch MacBook Pro is here

Happy MacBook Pro Day.

The new 16-inch model replaces the 15-inch option and starts at $2399.

It has inverted-“T” arrow keys, a physical escape key, and higher-travel scissor key switches.

Community Thoughts

Jason Snell:

Apple doesn’t like to admit that it’s wrong, but will be the first to let you know when it’s made an improvement.

[…]

I just wrote 2,000 words about a new Apple laptop on that laptop’s keyboard, and it went just fine. That’s reason enough to party like it’s 2015.

Stephen Hackett:

[The thermal changes] should give Apple more headroom for future spec bumps, as Intel CPUs don’t seem to be getting much cooler anytime soon.

[…]

The MacBook line’s reputation has been tarnished by this [keyboard] problem for years, and it’s going to take years to recover. The changes to the escape and arrow keys will help, but Apple needs to get this keyboard into the smaller MacBook Pro and MacBook Air as soon as it can.

Marco Arment:

Five years ago, laptop keyboards were fine. Everyone was pretty much satisfied with the ones they had, they worked, and we never had to talk or think about them.

Today, finally, we begin heading back to that world.

Escaping Shortcuts After Running a Shortcut

Save yourself a gesture and send yourself right to the homescreen when your shortcut has completed with this workaround from the r/shortcuts subreddit:

  1. Install a launcher app that allows you to open a URL to visit the homescreen. “Launcher with Multiple Widgets” is used in this example.
  2. Declare (“URL”) and open (“Open URLs”) the launcher’s homescreen URL. In this case, “launcher://homescreen” is used.

Here’s a screenshot of the actions described in step #2: The Launcher://homescreen URL Actions

The original Reddit post shows this solution in action.

The fact that this isn’t built right in to Shortcuts is unfortunate, but luckily third-party apps can fill this gap.