April 2017
Intermediate to advanced
316 pages
9h 33m
English
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"
Read now
Unlock full access