Files
YuJiWatch/YuJiWatchApp/WatchStore.swift
T

28 lines
833 B
Swift

import Foundation
/// 手表本地最近录音记录(仅用于手表端列表展示,真正笔记在 iPhone 端生成)
struct WatchNote: Identifiable, Codable {
var id = UUID()
var createdAt: Date
var duration: TimeInterval
var sent: Bool
}
enum WatchStore {
private static let key = "yujiWatchNotes"
static func load() -> [WatchNote] {
guard let data = UserDefaults.standard.data(forKey: key),
let notes = try? JSONDecoder().decode([WatchNote].self, from: data) else { return [] }
return notes.sorted { $0.createdAt > $1.createdAt }
}
static func append(_ note: WatchNote) {
var notes = load()
notes.append(note)
if let data = try? JSONEncoder().encode(notes) {
UserDefaults.standard.set(data, forKey: key)
}
}
}