構造内部の辞書型や列挙型のアクセス方法としてサブスクリプトを定義
/*
サブスクリプト
構造内部の辞書型や列挙型のアクセス方法としてサブスクリプトを定義
*/
struct TimesTable {
let multiplier: Int
subscript(index: Int) -> Int {
return multiplier * index
}
}
let threeTimesTable = TimesTable(multiplier: 3)
print("six times three is \(threeTimesTable[6])")