//获取沙盒文件夹路径
class func documentsDirectory()->String {
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory,
.UserDomainMask, true)
let documentsDirectory = paths.first!
let path = documentsDirectory + "/HomeIconClickNum"
return path
}
//拿取缓存的数组(点击的名字组成的数组)
let fileManager = NSFileManager.defaultManager()
if fileManager.fileExistsAtPath(self.documentsDirectory){
guard let OldArr = NSKeyedUnarchiver.unarchiveObjectWithFile(self.documentsDirectory) as? NSMutableSet else {return}
//添加新的数组元素
OldArr.addObject(imgDic.iconsName)
let arrData = NSKeyedArchiver.archivedDataWithRootObject(OldArr)
let isTureWrite = arrData.writeToFile(HomeIconStatistics.documentsDirectory(), atomically: false)
}else {
let NewArr = NSMutableSet()
//添加新的数组元素
NewArr.addObject(imgDic.iconsName)
let arrData = NSKeyedArchiver.archivedDataWithRootObject(NewArr)
let isTureWrite = arrData.writeToFile(HomeIconStatistics.documentsDirectory(), atomically: false)
print(isTureWrite)
}