SecureStorageSample/SecureStorageSample Watch App/Services/Handlers/UserProfileWatchHandler.swift

30 lines
745 B
Swift

import Foundation
import SharedKit
@MainActor
final class UserProfileWatchHandler: WatchDataHandling {
let key = UserProfile.storageKeyName
private let store: WatchProfileStore
private let decoder = JSONDecoder()
init(store: WatchProfileStore) {
self.store = store
}
convenience init() {
self.init(store: .shared)
}
func handle(data: Data) {
do {
let profile = try decoder.decode(UserProfile.self, from: data)
store.setProfile(profile)
Logger.debug("Watch synced user profile")
} catch {
store.setStatus("Failed to decode profile")
Logger.error("Watch failed to decode user profile", error: error)
}
}
}