I was using the code below to set an HKQueryAnchor
when making a HKAnchoredObjectQuery
however 'unarchiveObject(with:)' has been deprecated and I can't figure out how to write it with the new API?
private func getAnchor() -> HKQueryAnchor? {
let encoded = UserDefaults.standard.data(forKey: AnchorKey)
if(encoded == nil){
return nil
}
let anchor = NSKeyedUnarchiver.unarchiveObject(with: encoded!) as? HKQueryAnchor
return anchor
}
private func saveAnchor(anchor : HKQueryAnchor) {
let encoded = NSKeyedArchiver.archivedData(withRootObject: anchor)
defaults.setValue(encoded, forKey: AnchorKey)
defaults.synchronize()
}