正在尝试解决错误 "Ambiguous reference to member 'subscript'"

Trying to solve the error "Ambiguous reference to member 'subscript'"

首先我创建了一些列表:

let day0 = [0] as NSArray
let day1 = [0, 8, 2, 3, 4] as NSArray
let day2 = [0, 1, 2, 3, 4] as NSArray
let day3 = [0, 1, 2, 3, 4] as NSArray
let day4 = [0, 1, 2, 3, 4] as NSArray

let month0 = [0] as NSArray
let january = [day0, day1, day2, day3, day4] as NSArray
let february = [day0, day1, day2, day3, day4] as NSArray
let march = [day0, day1, day2, day3, day4] as NSArray
let april = [day0, day1, day2, day3, day4] as NSArray
let may = [day0, day1, day2, day3, day4] as NSArray
let june = [day0, day1, day2, day3, day4] as NSArray
let july = [day0, day1, day2, day3, day4] as NSArray
let august = [day0, day1, day2, day3, day4] as NSArray
let september = [day0, day1, day2, day3, day4] as NSArray
let october = [day0, day1, day2, day3, day4] as NSArray
let november = [day0, day1, day2, day3, day4] as NSArray
let december = [day0, day1, day2, day3, day4] as NSArray

let calendar = [month0, january, february, march, april, may, june, july, august, september, october, december] as NSArray

然后我尝试return一个元素:

@IBAction func SetVariablesButton(sender: UIButton)
{
    var result = calendar[1][1][1] as String
    BedTimeLabel.text = String(result)
}

然后我得到了错误。我尝试了各种更改,例如

let day0 = [0] as! NSArray

let day0 = [0] as Array<T>

但这些都不起作用。 我最初根本不转换 vars,但在研究了常见问题之后,常见的解决方案是转换 vars,以便编译器可以理解发生了什么。 我正在使用 Xcode 8 和 Swift 2.3

首先将 dummymonth0 声明为 [[0]] 以获得与其他月相同的类型。

然后删除 所有 演员表。

let day0 = [0]
let day1 = [0, 8, 2, 3, 4]
let day2 = [0, 1, 2, 3, 4]
let day3 = [0, 1, 2, 3, 4]
let day4 = [0, 1, 2, 3, 4]

let month0 = [[0]]
let january = [day0, day1, day2, day3, day4]
let february = [day0, day1, day2, day3, day4]
let march = [day0, day1, day2, day3, day4]
let april = [day0, day1, day2, day3, day4]
let may = [day0, day1, day2, day3, day4]
let june = [day0, day1, day2, day3, day4]
let july = [day0, day1, day2, day3, day4]
let august = [day0, day1, day2, day3, day4]
let september = [day0, day1, day2, day3, day4]
let october = [day0, day1, day2, day3, day4]
let november = [day0, day1, day2, day3, day4]
let december = [day0, day1, day2, day3, day4]

let calendar = [month0, january, february, march, april, may, june, july, august, september, october, december]

编译器可以推断出 calendar[[[Int]]]

现在你可以写了

var result = String(calendar[1][1][1])