【发布时间】:2019-03-11 17:25:56
【问题描述】:
我的任务是从iCloud 中选择files,它是url,title,etc.,然后附加到项目array。之后,我在struct 的帮助下获取每个值并在tableView 中列出。
在这里,我需要了解一件事,如何validate 用户选择的文件已经存在或不存在到我的数组中。如果存在,我不允许在他们的文件中附加alert 消息。
// Array Declaration
var items = [Item]()
var tableArray = [Item]()
// Values appending into my array
items.append(Item(url: fileurl, title: filename, exten: fileextension, size: string))
// Tableview data load
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomTableViewCell
let item = tableArray[indexPath.row]
if tableArray.count > 0 {
cell.name_label_util.text = item.title
cell.size_label_util.text = item.size
}
return cell
}
【问题讨论】:
-
您需要出示您的物品声明。您需要使您的
Item结构 Equatable 并在附加之前检查您的数组是否包含它