最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

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

Swift crifan 579浏览 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,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
60 queries in 0.095 seconds, using 18.82MB memory