&#39;阵列&#39;与&#39; Array <t>&#39;不相同为什么会出现以下代码?</t>

时间:2014-10-17 10:10:12

标签: ios arrays swift

我必须从Array中选择值并将其分配给String变量。

var selectedCountryCode:String = ""
var countryCodesArray:Array = ["+1","+977","+93","+355","+213","+1684"]

didSelectRowAtIndexPath中,我需要根据indexPath将所选值存储在变量中,如下所示,但我收到**'Array' is not identical to 'Array<T>'**错误。

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
    selectedCountryCode = countryCodesArray[indexPath.row]  //Here issue is coming

    println(selectedCountryCode)
}

请告诉我这个问题背后的原因和逻辑是什么以及如何解决?

1 个答案:

答案 0 :(得分:3)

尝试以下方法:

var countryCodesArray: [String] = ["+1","+977","+93","+355","+213","+1684"]

甚至更好

var countryCodesArray = ["+1","+977","+93","+355","+213","+1684"]

由于您缺少通用参数,上述内容甚至无法编译。