![Swift Functional Programming(Second Edition)](https://wfqqreader-1252317822.image.myqcloud.com/cover/293/36701293/b_36701293.jpg)
上QQ阅读APP看书,第一时间看更新
Subscripts
Subscripts are shortcuts to access the member elements of a collection, list, sequence, or any custom type that implement subscripts. Consider the following example:
struct TimesTable {
let multiplier: Int
subscript(index: Int) ->Int {
return multiplier * index
}
}
let fiveTimesTable = TimesTable(multiplier: 5)
print("six times five is \(fiveTimesTable[6])")
// prints "six times five is 30"