1 本地目录数据删除
let fm = FileManager.default 、
do{
tryfm.removeItem(atPath: removeFolder)
setNavigationTitle() // 获取数据的所有条数
}
catch{
print("ERROR: can't remove folder @ ContentsViewController")
}
2 本地数据获取条数
代码如下:
func getShotCount() -> Int{
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
letbasePath:String= paths[0]
letfm =FileManager.default
varfolderArray :NSArray= []
do{
letfolderArrayRaw =tryfm.contentsOfDirectory(atPath: basePath)
folderArray = folderArrayRaw.sorted(by: {(s1, s2)inreturns2 < s1})asNSArray
}
catch{
// siwft2.3 convert
print("NSError")
vari =0
foriteminfolderArray {
varisdirectory : ObjCBool =false
lettmpPath = basePath +"/"+ (itemas!String)
iffm.fileExists(atPath: tmpPath,isDirectory: &isdirectory){
if!isdirectory.boolValue{
i = i +1
}
}
}
letshotCount = folderArray.count- i
returnshotCount
}
网友评论