0

まず、いくつかのリストを作成します。

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

次に、要素を返そうとします:

@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>

しかし、それらはうまくいきませんでした。最初は変数をまったくキャストしませんでしたが、一般的な問題を調査した後、一般的な解決策は変数をキャストして、コンパイラが何が起こっているかを理解できるようにすることでした。Swift 2.3でXcode 8を使用しています

4

1 に答える 1