2
我有這樣的代碼:寫作字符串給我的錯誤,寫入圖像不
let image = UIImage(data: downloadedImage!)
let convertImage = UIImagePNGRepresentation(image!)
let pathUIDImage = self.getDocumentsDirectory().appendingPathComponent(playersUID + "Image")
try? convertImage!.write(to: pathUIDImage) //working
let playersUIDImageVersion = "1"
var pathUIDImageVersion = self.getDocumentsDirectory().appendingPathComponent(playersUID + "ImageVersion")
try? playersUIDImageVersion.write(to: pathUIDImageVersion) //error
的錯誤是:
無法將類型「URL」預期儀器類型的值「inout_」
當我更換嘗試? playersUIDImageVersion嘗試? convertImage!錯誤消失了。將不同類型的值寫入目錄有什麼區別?謝謝。下面的函數getDocumentsDirectory
func getDocumentsDirectory() -> URL {
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
let documentsDirectory = paths[0]
return documentsDirectory
}
謝謝,這個伎倆。使用適當的文件擴展名意味着什麼?我在哪裏以及如何添加它們? – Petravd1994
您的圖像應該命名爲'playersUID +「Image.png」'和字符串'playersUID +「ImageVersion.txt」' – vadian
謝謝!!!!!! – Petravd1994