0
將pathArray作爲fileURLWithPath
傳遞時出現錯誤。類型「URL」沒有類型「fileURL」 - 無法將字符串數組作爲字符串傳遞
func downloadImageForPhoto(_ photo: Photo, completionHandler: @escaping (_ success: Bool, _ errorString: String?) -> Void) {
taskForGETMethod(photo.photoURL, parameters: nil, parseJSON: false) { (result, error) in
if error != nil {
photo.imagePath = "unavailable"
completionHandler(false, "Unable to download Photo")
} else {
if let result = result {
DispatchQueue.main.async(execute: {
let fileName = (photo.photoURL as NSString).lastPathComponent
let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
let pathArray = [path, fileName]
let fileURL = URL(fileURLWithPath: "\(pathArray)")
FileManager.default.createFile(atPath: fileURL.path, contents: result as? Data, attributes: nil)
photo.imagePath = fileURL.path
completionHandler(true, nil)
})
} else {
completionHandler(false, "Unable to download Photo")
}
}
}
}
謝謝你的幫忙先生:) –