2016-10-06 2 views
0

Swift 2.0을 3.0으로 마이그레이션 한 후 " '같이 IndexOf를'때문에 '내부'보호 수준에 액세스 할 수 없습니다"스위프트 3 : 나는 문제가 몇 가지 실수를했다'내부'보호 수준으로 인해 'indexOf'에 액세스 할 수 없습니다.

// 코드

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

스위프트 3에서는 지금 '지수 (".")' –

+0

답장을 보내 주셔서 감사합니다. @nirav-d 'index (of : ".")'사용할 때 :이 오류가 발생했습니다 : '(of :) 인수 레이블이 사용 가능한 오버로드와 일치하지 않습니다. –

+0

문자열에서 분수 부분을 원하십니까? 예를 들어 "12.56"-> 56을 원해, 그렇지? –

답변

1

는 다음과 같이하십시오.

옵션 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"]