Cannot convert value of type 'Int' to expected argument type 'Index' (aka 'String.CharacterView.Index')
This is because the subscripting functions in String
no longer operate on ints, but on the inner Index
type:
extension String {
public typealias Index = String.CharacterView.Index
//...
public subscript (i: Index) -> Character { get }
So you need to grab some Index
values. You can achieve this by obtaining the first index in the string (aka the index of the first character), and navigate from there:
func tail(s: String) -> String {
return s.substringFromIndex(s.startIndex.advancedBy(1))
}
Note that the above code no longer compiles in the latest Swift version, I'll leave for historical purposes and for people stuck in earlier Swift.
These days we can write something along the lines of
extension String {
var tail: String { String(self[index(startIndex, offsetBy: 1)...]) }
// or
var tail: String { String(self[index(after: startIndex)...]) }
// or even this
var tail: String { String(dropFirst()) }
}