Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

swift

xcode7.3

I'm using the following code:

var continousDigitsRange:Range<Int> = Range<Int>(start: 0, end: 0)

Since update to Xcode 7.3 (Swift 2.2) I got the following hint:

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

For me is not clear how to "translate" it correctly with "using the '..<' operator.

like image 823
mahega Avatar asked Mar 22 '16 14:03

mahega


3 Answers

You should simply write

var continousDigitsRange1:Range<Int> = 0..<0

or if you want to go even simpler

var continousDigitsRange = 0..<0
like image 51
Scott Thompson Avatar answered Sep 25 '22 12:09

Scott Thompson


Also worth noting, to substringWithRange a String, you can now use

let theString = "Hello, how are you"
let range = theString.startIndex.advancedBy(start) ..< theString.startIndex.advancedBy(end)
theString.substringWithRange(range)
like image 36
bmichotte Avatar answered Sep 23 '22 12:09

bmichotte


The closed range operator (a...b) defines a range that runs from a to b, and includes the values a and b. The value of a must not be greater than b.

The half-open range operator (a..<b) defines a range that runs from a to b, but does not include b. It is said to be half-open because it contains its first value, but not its final value. As with the closed range operator, the value of a must not be greater than b. If the value of a is equal to b, then the resulting range will be empty.

The Swift Programming Language (Swift 2.2) - Basic Operators

var continousDigitsRange:Range<Int> = Range<Int>(start: 0, end: 0)
--to--
var continousDigitsRange:Range<Int> = 0..<0
like image 29
solenoid Avatar answered Sep 23 '22 12:09

solenoid