无法下标类型'[String]'的值

时间:2015-10-25 04:12:24

标签: swift

我在if语句中收到错误消息

if (SelectedJobFunctions.contains(JobFunctions[indexPath.row])){
            cell.accessoryType = .Checkmark
        }
        else {
            cell.accessoryType = .None
        }

这是数组

var JobFunctions = ["Cleaning","Admin","Slacking","Business"]
var SelectedJobFunctions = [] 

我试图查看用户是否已选择某个功能,如果已选择该功能将在SelectedJobFunctions数组中,则会添加一个复选标记

1 个答案:

答案 0 :(得分:0)

尝试在SelectedJobFunctions中指定数组类型,例如

   var JobFunctions = ["Cleaning","Admin","Slacking","Business"]
   var SelectedJobFunctions:[String] = []
   if (SelectedJobFunctions.contains(JobFunctions[indexPath.row])){
               cell.accessoryType = .Checkmark
   }
   else {
              cell.accessoryType = .None
   }