官术网_书友最值得收藏!

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"
主站蜘蛛池模板: 济源市| 普安县| 连南| 荆州市| 开封县| 平阴县| 海阳市| 拜泉县| 娄烦县| 新兴县| 白城市| 广元市| 余江县| 都兰县| 牡丹江市| 张北县| 澎湖县| 章丘市| 大竹县| 新竹市| 耒阳市| 内乡县| 开鲁县| 公主岭市| 禹城市| 郧西县| 德保县| 大竹县| 眉山市| 沾益县| 威信县| 奉化市| 哈巴河县| 依安县| 灵宝市| 攀枝花市| 斗六市| 瓦房店市| 惠水县| 商洛市| 耿马|