我有代码:
struct FilesToDownload {
var fileInternetUrl: String?
var fileName: String?
var savedURL: String?
var productImageUrl: URL?
var fileSize: Int
}
var filesToDownload = [FilesToDownload]()
func startDownloadFiles(filesArray: [FilesToDownload], filesType: Int){
for files in filesArray{
print("- files.fileName")
// here remove element files.fileName from array filesToDownload
}
}
如何从startDownloadFiles数组中删除当前显示的元素files.fileName?
答案 0 :(得分:1)
您只需在filesToDownload
数组中找到与files.fileName
匹配的对象的索引,然后删除该索引的元素形式
if let index = filesToDownload.index(where: {$0.fileName.lowercased() == files.fileName.lowercased() }) {
filesToDownload.remove(at:index)
}