//
//  SpeakCache.swift
//  SpeakEasyLearnEnglish
//
//  Created by edy on 2025/7/25.
//

import UIKit

class SpeakCache: NSObject {
    
    static let cache = SpeakCache()
    
    private let dir = "SpeakCache"
    private let headerName = "avatar.png"
    
    private override init() {
        dir.documentURL().isDirect(true)
    }
    
    /// 保存头像
    func Save(data:Data?) -> Void {
        if let d = data {
            let url = dir.documentURL().appendingPathComponent(headerName)
            do {
                try d.write(to: url)
            }catch{}
        }
    }
    
    /// 加载本地头像
    func loadHeader() -> UIImage {
        let url = dir.document() + "/\(headerName)"
        let icon = UIImage(contentsOfFile: url)
        return icon ?? UIImage(named: "img_touxiang")!
    }
}
