//
|
// SearchHistorySave.swift
|
// XiaoKeProject
|
//
|
// Created by alvin_y on 2019/8/16.
|
// Copyright © 2019 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
|
// 文件地址
|
let accountPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first! + "/address.plist"
|
|
|
|
|
class SearchHistoryModel: NSObject,Codable {
|
|
var name = ""
|
}
|
|
class SearchHistorySave: NSObject {
|
|
class func saveFile(model: SearchHistoryModel) {
|
|
var array = readFile()
|
//去重
|
for (value,item) in array.enumerated() {
|
if item.name == model.name{
|
array.remove(at: value)
|
}
|
}
|
array.insert(model, at: 0)
|
if array.count > 6{
|
array.remove(at: 6)
|
}
|
NSKeyedArchiver.archiveRootObject(array, toFile: accountPath)
|
|
}
|
|
class func readFile() -> [SearchHistoryModel] {
|
let array:[SearchHistoryModel] = NSKeyedUnarchiver.unarchiveObject(withFile: accountPath) as? [SearchHistoryModel] ?? []
|
return array
|
}
|
|
class func clearFile() {
|
NSKeyedArchiver.archiveRootObject([], toFile: accountPath)
|
}
|
}
|