「Swift学習」subscript syntaxを利用するサンプルコード
サンプルコード:
struct startnews24 {
let offset:Int
var textCount:Int
subscript(index:Int) -> Int{
get{
return index – offset
}
set(newvalue){
textCount = newvalue * 3
}
}
}
var startnews24 = startnews24(offset:2,textCount:0)
startnews24[9] //7
startnews24[9] = 8 //startnews24.textCount 24