Search code examples
swifthealthkit

Adding an array of HKWorkouts to UserDefaults


Is there anyway to add an array of HKWorkouts to UserDefaults or do I have to save the array in core data?


Solution

  • HKObject and its subclasses conform to NSSecureCoding, so you can convert an array of them to Data using NSKeyedArchiver. See the NSKeyedArchiver documentation for more details.