由于 'internal' 保护级别,'indexOf' 无法访问

'indexOf' is inaccessible due to 'internal' protection level

将 Swift 2.0 迁移到 3.0 后。我有一些错误,我遇到了问题:“'indexOf' 由于 'internal' 保护级别而无法访问” Swift 3:

//代码

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)
                                }
                            }
                        }
                    }

这样试试。

选项 1

let mynum = "26.53"
if let range = mynum.range(of: ".") {
    let num1 = mynum.substring(to: mynum.index(range.lowerBound, offsetBy: 0)) // 26
    let num = mynum.substring(from: mynum.index(after: range.lowerBound)) // 53 
}

选项 2

let numArr = mynum.characters.split(separator: ".").map(String.init) // ["26","53"]

选项 3

let numArr = mynum.components(separatedBy: ".") // ["26","53"]