WatchThemeStore.swift 592 Bytes
import Foundation

/// Shared Watch theme persistence.
/// The Watch app and Widget extension read this exact JSON string from App Group.
final class WatchThemeStore {
  static let shared = WatchThemeStore()

  private init() {}

  @discardableResult
  func saveThemeJSONString(_ json: String) -> Bool {
    guard json.data(using: .utf8) != nil else { return false }
    AppGroupConstants.defaults?.set(json, forKey: AppGroupConstants.Key.myWatchTheme)
    return true
  }

  func clearTheme() {
    AppGroupConstants.defaults?.removeObject(forKey: AppGroupConstants.Key.myWatchTheme)
  }
}