我正在製作一個應用程序,當您按下一個按鈕表示它很緊急時,會有一個標籤顯示爲「URGENT」。就在我實現與按鈕的用戶交互之前,我有一個數組(如下所示),其中一些對象具有urgent = true
,但有一些具有urgent = false
,所以我可以從我的代碼開始。錯誤:無法爲類型'inout [Agenda]'(aka'inout Array <Agenda>')下標值'
的陣列,其是在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 = ""
}
在第一行,我得到以下錯誤:
Cannot subscript a value of type 'inout [Agenda]' (aka 'inout Array')
如果content [indexPath.row] .urgent = true {'應該是'if content [indexPath.row] .urgent {' – dan
或==而不是=(賦值語句在Swift中什麼都不返回) –
@VinceBurn謝謝:) –