在swift中替代.successor()?

时间:2015-09-20 13:44:52

标签: swift

let greeting = "Guten Tag!"

greeting[greeting.startIndex.successor()] 
// "u"

greeting[greeting.startIndex.successor().successor().successor()]
// "e"

有没有其他选择,而不是多次写.successor()

1 个答案:

答案 0 :(得分:1)

Swift 2.0 中,这是advancedBy

greeting[greeting.startIndex.advancedBy(3)]  // "e"

Swift 1.2

greeting[advance(greeting.startIndex, 3)]  // "e"