我正在制作一个应用程序,当您按下按钮说它很紧急时,会显示一个标签“URGENT”。在实现与按钮的用户交互之前,我有一个数组(如下所示),其中一些对象具有urgent = true
,但有些对象具有urgent = false
,所以我可以从我的代码开始。
数组,在MainTableViewController.swift
中:
var content:[Agenda] = [
Agenda(subject: "Read this article", deadline: "1-2 days", urgent: false),
Agenda(subject: "Respond to this email", deadline: "ASAP", urgent: true),
Agenda(subject: "Add this to diary", deadline: "When at home", urgent: true),
Agenda(subject: "Listen to this song", deadline: "When finished working", urgent: false),
Agenda(subject: "Check out this holiday destination", deadline: "At the weekend", urgent: false),
Agenda(subject: "Download this podcast", deadline: "1-4 days", urgent: false),
Agenda(subject: "Update notes", deadline: "When at home", urgent: true)
]
然后,我有一个名为
Agenda.swift
的类,在其中声明了subject
,deadline
和urgent
。这是我是否显示“紧急”的代码:
if content[indexPath.row].urgent = true {
cell.urgentLabel.text = "URGENT"
} else {
cell.urgentLabel.text = ""
}
在第一行,我收到以下错误:
无法下标'inout [Agenda]'类型的值(也称为'inout Array')
最佳答案
这是经典的赋值运算符(=
)与方程式运算符(==
)的混淆。
关于ios - 错误:无法下标'inout [Agenda]'类型的值(又名'inout Array <Agenda>'),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35818524/