【发布时间】:2016-10-06 10:51:21
【问题描述】:
在将 Swift 2.0 迁移到 3.0 之后。我有一些错误,我遇到了问题:Swift 3 上的“'indexOf' is inaccessible due to 'internal' protection level”:
// 代码
var indexIndexed = 0
for link in doc.css("li") {
if(link.className == "regular-search-result"){
for link2 in link.css("span") {
if(link2.className == "indexed-biz-name"){
let num:String = link2.text!
let lastPart = num.substring(to: num.index(num.startIndex, offsetBy: num.indexOf(".")!)) // Here
print("le num est \(lastPart)")
let numInt:Int = Int(lastPart)!
if(numInt > 10 && numInt <= 20){
indexIndexed = numInt - 10
} else if(numInt > 20){
indexIndexed = numInt - 20
} else {
indexIndexed = numInt
}
//print(indexIndexed)
}
}
}
}
【问题讨论】:
-
在 Swift 3 中它现在是
index(of: ".") -
感谢您的回复。 @nirav-d 当我使用
index(of: ".")时出现此错误:参数标签 '(of:)' 不匹配任何可用的重载 -
你想要字符串的小数部分吗?例如“12.56”->你想要 56,对吧?
-
是的,但我在这里使用 indexOf:
let firstPart = link.innerHTML!.substringFrom(link.innerHTML!.startIndex.advancedBy(link.innerHTML!.index(of:"href=\"")!+6)) -
您能在问题中添加清晰的示例吗?
标签: swift string swift3 indexof