다음은 Xcode-8 이전 Swift 호출입니다.
func gappizeAtDoubleNewlines()
{
let t = self.text!
var index = t.startIndex
var follow = index.advancedBy(1)
for i in 0 ..< (t.characters.count-4)
{
let r = index ... follow
if ( t.substringWithRange(r) == "\n\n" )
{ alterLineGapHere(i) }
index = index.advancedBy(1)
follow = index.advancedBy(1)
}
}
Swift3로 자동 업그레이드를 사용하면 이러한 오류가 발생했습니다.
텍스트에서
func gappizeAtDoubleNewlines()
{
let t = self.text!
var index = t.startIndex
var follow = <#T##Collection corresponding to `index`##Collection#>.index(index, offsetBy: 1)
for i in 0 ..< (t.characters.count-4)
{
let r = index ... follow
if ( t.substring(with: r) == "\n\n" )
{ alterLineGapHere(i) }
index = <#T##Collection corresponding to `index`##Collection#>.index(index, offsetBy: 1)
follow = <#T##Collection corresponding to `index`##Collection#>.index(index, offsetBy: 1)
}
}
Swift3의 솔루션은 무엇입니까?
SE-0065 : '컬렉션이 인덱스를 이동합니다'를 참조하십시오 . 이 경우 편집기 자리 표시자를 다음으로 대체 할 수 있습니다 t
.
func gappizeAtDoubleNewlines() {
let t = self.text!
var index = t.startIndex
// Note that because substring(by:) takes a Range<String.Index>, rather than
// a ClosedRange, we have to offset the upper bound by one more.
var follow = t.index(index, offsetBy: 2)
for i in 0 ..< (t.characters.count-4) {
let r = index ..< follow
if (t.substring(with: r) == "\n\n") {
alterLineGapHere(i)
}
index = t.index(index, offsetBy: 1)
follow = t.index(follow, offsetBy: 1)
}
}
참고 있지만 String
하지 않는 것입니다 Collection
자체가, 그냥 그 기대에 색인에 대한 몇 가지 편리한 메소드를 구현 t.characters
, 이다 을 Collection
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다