语记手表版 v0.1:一键录音、WatchConnectivity 传输、表盘复杂功能、iPhone 接收转写
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user