如何检查索引是否是数组中的最后一个

Hun*_*ter 1 arrays xcode swift

嘿,我正在尝试创建一个 if 语句来遍历整个数组,然后询问该索引是否是数组中的最后一个。

这是我到目前为止所拥有的。

代码:

 func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)  { // Called for each cell made

  if notificationList[indexPath.row] == notificationList.last! {

        print("At last index")

   }
}
Run Code Online (Sandbox Code Playgroud)

更新:

实际上我认为这可行,但我会采取其他答案

Vib*_*ngh 5

检查如下

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)  { 

  if indexPath.row == notificationList.count - 1 {

        print("At last index")

   }
}
Run Code Online (Sandbox Code Playgroud)