最佳答案
我希望将字符串中包含的字母的索引转换为整数值。尝试读取头文件,但是我找不到 Index
的类型,尽管它似乎符合使用方法(例如 distanceTo
)的协议 ForwardIndexType
。
var letters = "abcdefg"
let index = letters.characters.indexOf("c")!
// ERROR: Cannot invoke initializer for type 'Int' with an argument list of type '(String.CharacterView.Index)'
let intValue = Int(index) // I want the integer value of the index (e.g. 2)
感谢你的帮助。