//
//  SpeakWordTranslateData.swift
//  SpeakEasyLearnEnglish
//
//  Created by edy on 2025/7/31.
//

import UIKit


/// 单词翻译数据
class SpeakWordTranslateData: NSObject {

    static let data = SpeakWordTranslateData()
    
    var WordTranslate:[Int:SpeakPracticeWordDetailModel]?
    private let fileUrl = "SpeakCache".documentURL().appendingPathComponent("WordTranslate.data")
    func loadData() -> Void {
        do {
            let data = try Data(contentsOf: fileUrl)
            WordTranslate = try JSONDecoder().decode([Int:SpeakPracticeWordDetailModel].self, from: data)
        }catch{
            WordTranslate = [:]
        }
    }
    
    func SaveData() -> Void {
        do{
            let data = try JSONEncoder().encode(WordTranslate)
            try data.write(to: fileUrl)
        }catch{}
    }
    
    private override init() { }
}

