我下載一個JSON文件與此代碼使用的URL作爲名稱來保存文件
URLSession.shared.dataTask(with: NSURL(string: url)! as URL, completionHandler: { (data, response, error) -> Void in
if let this = weakSelf{
,然後我嘗試將其保存在本地
let fileURL = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false).appendingPathComponent(url)
print(fileURL)
try data?.write(to: fileURL)
} catch {
print(error)
}
我想使用的網址JSON文件作爲我嘗試保存時的名稱。但我得到一個錯誤告訴我,路徑不存在...每一個想法的工作文件,我試圖用一個正常的名字保存它。你有如何解決這個問題的想法?
當print(fileURL)執行時,它打印什麼? – 3stud1ant3