Skip to content

Latest commit

 

History

History
12 lines (12 loc) · 287 Bytes

File metadata and controls

12 lines (12 loc) · 287 Bytes

1.Subscript Syntax

struct TimesTable {
    let multiplier: Int
    subscript(index: Int) -> Int {
        return multiplier * index
    }
}
let threeTimesTable = TimesTable(multiplier: 3)
print("six times three is \(threeTimesTable[6])")
// Prints "six times three is 18"