You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SwiftUI中FileManager.copyItem报错「文件不存在」求助

SwiftUI中使用LLMFarm Core下载模型时临时文件不存在的问题

问题描述

我是SwiftUI初学者,正在练习用LLMFarm Core搭建本地大语言模型。执行代码try FileManager.default.copyItem(atPath: temporaryURL.path, toPath: fileURL.path)时,出现错误:Error: The file “CFNetworkDownload_rr8uC6.tmp” doesn’t exist.,推测问题出在temporaryURL变量上。

相关代码

status = "downloading"
print("Downloading model \(modelName) from \(modelUrl)")
guard let url = URL(string: modelUrl) else { return }
let fileURL = getFileURLFormPathStr(dir:"models",filename: filename)
downloadTask = URLSession.shared.downloadTask(with: url) { temporaryURL, response, error in
    if let error = error {
        return
    }
    guard let response = response as? HTTPURLResponse, (200...299).contains(response.statusCode) else {
        print("Server error!")
        return
    }
    do {
        if let temporaryURL = temporaryURL {
            try FileManager.default.copyItem(atPath: temporaryURL.path, toPath: fileURL.path)

已尝试的操作

  • 替换为try FileManager.default.copyItem(at: temporaryURL, to: fileURL),问题未解决
  • 参照LLMFarm示例完成所有权限配置和Info.plist属性设置
  • 在个人设备和M1电脑上测试,均出现相同错误
  • 在if let temporaryURL = temporaryURL上方添加判断if !FileManager.default.fileExists(atPath: fileURL.path),确认目标文件存在,但报错依旧

补充信息

  • temporaryURL的值:file:///Users/salman/Library/Containers/com.guinmoon.LLMFarm23/Data/tmp/CFNetworkDownload_QfLexg.tmp
  • fileURL的值:file:///Users/salman/Library/Containers/com.guinmoon.LLMFarm23/Data/Documents/models/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf
  • 代码仓库可直接克隆测试

内容的提问来源于stack exchange,提问作者salman mallick

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 04:56:29