The short answer is no. Static is limited to methods and properties within a structure or class. Subscribers are operators and cannot be set to static. This is doable:
struct TimesTable { let multiplier: Int subscript(index: Int) -> Int { return multiplier * index } } let threeTimesTable = TimesTable(multiplier: 3) print("six times three is \(threeTimesTable[6])")
but you need to make an object out of threeTimesTable (in this case). Also, it's worth a look at:
http://www.codingexplorer.com/custom-subscripts-swift/
source share