swift - What is the expected result of subscripting a range? -


i can't find documentation explaining subscripting range supposed do. i'd expect yield nth value of range, seems return subscripted value, itself.

let range = 10...20 let valuefromrange = range[2] 

in case, i'd expect valuefromrange equal 12, it's equal 2. seems case ranges (or, @ least ranges of type range<int> , range<double>).

is value i'm supposed get? besides defying think commonly expected behavior, behavior useless.

you should convert range array if want subscript that:

let range = array(10..20) range[2] // returns 12 

while can add range.startindex , subscript directly particular range, can't subscript strided ranges @ without converting them:

let range = (10..20).by(3) range[2] // error: 'stridedrangegenerator<int>' not have member named 'subscript' 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -