代码:
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.
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.