123456789101112131415161718192021222324252627282930313233343536373839 |
- //
- // KMAdvertisementCache.swift
- // KMAdvertisement
- //
- // Created by lizhe on 2022/11/25.
- //
- class KMAdvertisementCache: NSObject {
-
- let kFilePath: NSString = (NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, false).first?.appending("/advertisement.plist"))! as NSString
-
- //单例
- public static let `default` = KMAdvertisementCache()
- //存储
- func saveData(data: [NSDictionary]) {
- if (FileManager.default.fileExists(atPath: kFilePath as String)) {
- FileManager.default.createFile(atPath: kFilePath as String, contents: nil);
- }
-
- let saveData: NSArray = data as NSArray
- let success = saveData.write(toFile: kFilePath.expandingTildeInPath as String, atomically: true)
- if (success == true) {
- print("成功 -" + (kFilePath.expandingTildeInPath as String))
- } else {
- print("失败 -" + (kFilePath.expandingTildeInPath as String))
- }
- }
- //读取
- func readData() -> [NSDictionary] {
- let data = NSArray.init(contentsOfFile: kFilePath.expandingTildeInPath as String)
- return data as! [NSDictionary]
- }
- //2.利用NSSearchPathForDirectoriesInDomains获取路径
- //
- //
- }
|