123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- //
- // TestDegreeManager.swift
- // KdanAuto
- //
- // Created by 朱东勇 on 2023/2/9.
- //
- import Foundation
- class TestDegreeManager : NSObject {
- var degreeInfo = NSMutableDictionary()
-
- static var tdManager = TestDegreeManager()
- class func shared() -> TestDegreeManager {
- return tdManager
- }
-
-
- override init() {
- var path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
- path = NSString(string: path).appendingPathComponent("TestDegreeData.plist");
-
- if let info = try? NSDictionary.init(contentsOfFile: path) {
- degreeInfo = NSMutableDictionary.init(dictionary: info);
- }
- }
-
- func saveInfo() {
- var path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
- path = NSString(string: path).appendingPathComponent("TestDegreeData.plist");
-
- try! degreeInfo.write(toFile: path, atomically: true)
- }
-
-
- // Clear
- func clearAllHistory() {
- degreeInfo.removeAllObjects()
- }
-
- // Set
- func set(_ degree:Double, fileType:String?) {
- set(degree, fileType: fileType, type: nil)
- }
-
- func set(_ degree:Double, fileType:String?, type:String?) {
- set(degree, fileType: fileType, type: type, fileName: nil)
- }
-
- func set(_ degree:Double, fileType:String?, type:String?, fileName:String?) {
- set(degree, fileType: fileType, type: type, fileName: fileName, refFilePath: nil)
- }
-
- func set(_ degree:Double, fileType:String?, type:String?, fileName:String?, refFilePath:String?) {
- let key = String((fileType ?? "") + (type ?? "") + (fileName ?? "") + (refFilePath ?? ""))
-
- let number = NSNumber(floatLiteral: degree)
- objc_sync_enter(self)
- degreeInfo.setValue(number, forKey: key)
- objc_sync_exit(self)
- }
-
- //Get
-
- func degreeFor(_ fileType:String?) -> Double {
- return degreeFor(fileType, type: nil)
- }
-
- func degreeFor(_ fileType:String?, type:String?) -> Double {
- return degreeFor(fileType, type: type, fileName: nil)
- }
-
- func degreeFor(_ fileType:String?, type:String?, fileName:String?) -> Double {
- return degreeFor(fileType, type: type, fileName: fileName, refFilePath: nil)
- }
-
- func degreeFor(_ fileType:String?, type:String?, fileName:String?, refFilePath:String?) -> Double {
- let key = String((fileType ?? "") + (type ?? "") + (fileName ?? "") + (refFilePath ?? ""))
-
- if nil != degreeInfo.value(forKey: key) {
- let number = degreeInfo.value(forKey: key) as! NSNumber
- return number.doubleValue
- }
-
- return 0.0
- }
-
-
- }
- // File Info
- extension NSMutableDictionary {
- func degree() -> Double {
- return TestDegreeManager.shared().degreeFor(self.objc().fileType(),
- type: self.objc().type(),
- fileName: self.fileName(),
- refFilePath: self.refFilePath())
- }
- }
|