在Swift游乐场(Xcode 7)中,为什么会出现以下内容
var someString = "my four word string"
someString.substringFromIndex(advance(someString.startIndex, 5))
产生此错误:
'预先'不可用:拨打' advanceBy(n)'在索引上
答案 0 :(得分:2)
在Swift 2中,您应该使用[String].advanceBy([Int])
代替advance([String], [Int])
var someString = "my four word string"
someString.substringFromIndex(someString.startIndex.advancedBy(5))
答案 1 :(得分:-1)
以下是Swift 2.0中子字符串的代码:
var givenString = "some string"
let subString = givenString[someString.startIndex.advancedBy(4)] //some