Swift 3 and newer
You can offsetBy:
from .startIndex
:
let mySet: Set = ["a", "b", "c", "d"]
mySet[mySet.index(mySet.startIndex, offsetBy: 2)] // -> something from the set.
Swift 2 (obsolete)
You can advancedBy()
from .startIndex
:
let mySet: Set = ["a", "b", "c", "d"]
mySet[mySet.startIndex.advancedBy(2)] // -> something from the set.
Swift 1.x (obsolete)
Similar to String
, you have to advance()
from .startIndex
:
let mySet: Set = ["a", "b", "c", "d"]
mySet[advance(mySet.startIndex, 2)] // -> something from the set.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…