国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Swift > 正文

Swift實(shí)現(xiàn)文件壓縮和解壓示例代碼

2020-03-09 17:45:47
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

項(xiàng)目中有時(shí)候需要文件下載解壓,項(xiàng)目中選擇了ZipArchive,實(shí)際使用也比較簡(jiǎn)單,直接調(diào)用解壓和壓縮方法即可.

壓縮

@IBAction func zipAction(_ sender: UIButton) {  let imageDataPath = Bundle.main.bundleURL.appendingPathComponent("FlyElephant").path  zipPath = tempZipPath()  let success = SSZipArchive.createZipFile(atPath: zipPath!, withContentsOfDirectory: imageDataPath)  if success {   print("壓縮成功---/(zipPath!)")  } }

#解壓

@IBAction func unZipAction(_ sender: UIButton) {  guard let zipPath = self.zipPath else {   return  }  guard let unzipPath = tempUnzipPath() else {   return  }  let success = SSZipArchive.unzipFile(atPath: zipPath, toDestination: unzipPath)  if !success {   return  }  print("解壓成功---/(unzipPath)")  var items: [String]  do {   items = try FileManager.default.contentsOfDirectory(atPath: unzipPath)  } catch {   return  }  for (index, item) in items.enumerated() {   print("/(index)--文件名稱---/(item)")  } }

壓縮和解壓路徑:

func tempZipPath() -> String {  var path = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)[0]  path += "//(UUID().uuidString).zip"  return path } func tempUnzipPath() -> String? {  var path = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)[0]  path += "//(UUID().uuidString)"  let url = URL(fileURLWithPath: path)  do {   try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true, attributes: nil)  } catch {   return nil  }  return url.path }

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到swift教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 牟定县| 云梦县| 谢通门县| 三都| 华容县| 涞水县| 疏附县| 宜黄县| 阜新市| 兖州市| 淮北市| 扶风县| 夏河县| 临漳县| 谢通门县| 龙川县| 江西省| 萨迦县| 苍山县| 治县。| 温泉县| 邵武市| 清新县| 德江县| 桃园市| 中超| 时尚| 高雄市| 轮台县| 博爱县| 辽源市| 丰宁| 长宁区| 新丰县| 博客| 沁源县| 稷山县| 嘉定区| 县级市| 红原县| 集安市|