【发布时间】:2017-02-14 21:48:51
【问题描述】:
我正在尝试将我的 Swift 2.2 代码迁移到 Swift 3(beta),在迁移到 Swift 3.0 后,我在下面的代码中收到以下错误,“'String' 类型的值没有成员索引”
如果routePathComponent 是一个字符串,则需要帮助。
迁移后
if routePathComponent.hasPrefix(":") {
let variableKey = routePathComponent.substring(with: routePathComponent.indices.suffix(from: routePathComponent.characters.index(routePathComponent.startIndex, offsetBy: 1)))
}
迁移前
if routePathComponent.hasPrefix(":") {
let variableKey = routePathComponent.substringWithRange(routePathComponent.startIndex.advancedBy(1)..<routePathComponent.endIndex)
let variableValue = component.URLDecodedString()
if variableKey.characters.count > 0 && variableValue.characters.count > 0 {
variables[variableKey] = variableValue
}
}
【问题讨论】: