阅读背景:

swift -> 清除缓存 和 获取缓存大小

来源:互联网 

    *** 清空缓存 

//清除 Library/Caches func clearCaches(){ do { try deleteLibraryFolderContents(folder: "Caches") //print("clear done") } catch { //print("clear Caches Error") } } // private func deleteLibraryFolderContents(folder: String) throws { let manager = FileManager.default let library = manager.urls(for: FileManager.SearchPathDirectory.libraryDirectory, in: .userDomainMask)[0] let dir = library.appendingPathComponent(folder) let contents = try manager.contentsOfDirectory(atPath: dir.path) for content in contents { //如果是快照就继续 if(content == "Snapshots"){continue;} do { try manager.removeItem(at: dir.appendingPathComponent(content)) //print("remove cache success:"+content) } catch where ((error as NSError).userInfo[NSUnderlyingErrorKey] as? NSError)?.code == Int(EPERM) { //print("remove cache error:"+content) // "EPERM: operation is not permitted". We ignore this. #if DEBUG //print("Couldn't delete some library contents.") #endif } } } //清除 Library/Caches func clearCaches


你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: