//
//  SpeakLeassonData.swift
//  SpeakEasyLearnEnglish
//
//  Created by edy on 2025/8/5.
//

import UIKit

/// 首页课程列表
class SpeakLeassonData: NSObject {

    private let fileUrl = "SpeakCache".documentURL().appendingPathComponent("leasson.data")
    static let data = SpeakLeassonData()
    
    var leassionData:[SpeakHomeLessonModel] {
        set {
            do{
                let data = try JSONEncoder().encode(newValue)
                try data.write(to: fileUrl)
            }catch{}
        }
        get {
            var datas:[SpeakHomeLessonModel] = []
            do {
                let data = try Data(contentsOf: fileUrl)
                datas = try JSONDecoder().decode([SpeakHomeLessonModel].self, from: data)
            }catch{ }
            return datas
        }
    }
    
    private override init() { }
}
