最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】swift出错:’init(start:end:)’ is deprecated: it will be removed in Swift 3. Use the ‘..<‘ operator.

Swift crifan 1568浏览 0评论

代码:

        firstChar = str[Range(start: str.startIndex, end: str.startIndex.advancedBy(1))]

警告:

‘init(start:end:)’ is deprecated: it will be removed in Swift 3. Use the ‘..<‘ operator.

xcode7.3 – ‘init(start:end:)’ is deprecated: it will be removed in Swift 3. Use the ‘..<‘ operator – Stack Overflow

xcode7.3 – ‘init(start:end:)’ is deprecated: it will be removed in Swift 3. Use the ‘..<‘ operator – Stack Overflow

swift2.2 – ‘++’ is deprecated: it will be removed in Swift 3 – Stack Overflow

改为:

        //firstChar = str[Range(start: str.startIndex, end: str.startIndex.advancedBy(1))]
        firstChar = str[str.startIndex ..< str.startIndex.advancedBy(1)]

即可。

其他类似的代码也改为:

                //let greenHex = hex.substringWithRange(Range<String.Index>(start: hex.startIndex.advancedBy(1), end: hex.startIndex.advancedBy(2)))
                let greenHex = hex.substringWithRange(hex.startIndex.advancedBy(1) ..< hex.startIndex.advancedBy(2))
//            let greenHex = hex.substringWithRange(Range<String.Index>(start: hex.startIndex.advancedBy(2), end: hex.startIndex.advancedBy(4)))
            let greenHex = hex.substringWithRange(hex.startIndex.advancedBy(2) ..< hex.startIndex.advancedBy(4))
//            let blueHex = hex.substringWithRange(Range<String.Index>(start: hex.startIndex.advancedBy(4), end: hex.startIndex.advancedBy(6)))
            let blueHex = hex.substringWithRange(hex.startIndex.advancedBy(4) ..< hex.startIndex.advancedBy(6))

转载请注明:在路上 » 【已解决】swift出错:’init(start:end:)’ is deprecated: it will be removed in Swift 3. Use the ‘..<‘ operator.

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
85 queries in 0.178 seconds, using 22.05MB memory