The ++ and -- operators have been deprecated Xcode 7.3
A full explanation here from Chris Lattner, Swift's creator. I'll summarize the points:
- It's another function you have to learn while learning Swift
- Not much shorter than
x += 1
- Swift is not C. Shouldn't carry them over just to please C programmers
- Its main use is in C-style for loop:
for i = 0; i < n; i++ { ... }
, which Swift has better alternatives, likefor i in 0..<n { ... }
(C-style for loop is going out as well) - Can be tricky to read and maintain, for eg, what's the value of
x - ++x
orfoo(++x, x++)
? - Chris Lattner doesn't like it.
For those interested (and to avoid link rot), Lattner's reasons in his own words are:
These operators increase the burden to learn Swift as a first programming language - or any other case where you don't already know these operators from a different language.
Their expressive advantage is minimal - x++ is not much shorter than x += 1.
Swift already deviates from C in that the =, += and other assignment-like operations returns Void (for a number of reasons). These operators are inconsistent with that model.
Swift has powerful features that eliminate many of the common reasons you'd use ++i in a C-style for loop in other languages, so these are relatively infrequently used in well-written Swift code. These features include the for-in loop, ranges, enumerate, map, etc.
Code that actually uses the result value of these operators is often confusing and subtle to a reader/maintainer of code. They encourage "overly tricky" code which may be cute, but difficult to understand.
While Swift has well defined order of evaluation, any code that depended on it (like foo(++a, a++)) would be undesirable even if it was well-defined.
These operators are applicable to relatively few types: integer and floating point scalars, and iterator-like concepts. They do not apply to complex numbers, matrices, etc.
Finally, these fail the metric of "if we didn't already have these, would we add them to Swift 3?"
'++' is deprecated: it will be removed in Swift 3
Since Swift 2.2, you should use += 1
or -= 1
instead.
And after looking up Swift's evolution, there are some reasons for removing these operators:
These operators increase the burden to learn Swift as a first programming language - or any other case where you don't already know these operators from a different language.
Their expressive advantage is minimal - x++ is not much shorter than x += 1.
Swift already deviates from C in that the =, += and other assignment-like operations returns Void (for a number of reasons). These operators are inconsistent with that model.
Swift has powerful features that eliminate many of the common reasons you'd use ++i in a C-style for loop in other languages, so these are relatively infrequently used in well-written Swift code. These features include the for-in loop, ranges, enumerate, map, etc.
Code that actually uses the result value of these operators is often confusing and subtle to a reader/maintainer of code. They encourage "overly tricky" code which may be cute, but difficult to understand.
While Swift has well defined order of evaluation, any code that depended on it (like foo(++a, a++)) would be undesirable even if it was well-defined.
These operators are applicable to relatively few types: integer and floating point scalars, and iterator-like concepts. They do not apply to complex numbers, matrices, etc.
Finally, these fail the metric of "if we didn't already have these, would we add them to Swift 3?"
Please check out Swift evolution for more info.
'init(start:end:)' is deprecated: it will be removed in Swift 3. Use the '..' operator
You should simply write
var continousDigitsRange1:Range<Int> = 0..<0
or if you want to go even simpler
var continousDigitsRange = 0..<0
Unary operator '--' cannot be applied to an operand of type '@lvalue Int'
You should use use score = score + 1
instead of score++
How to replace the deprecated -- prefix decrement operator in comparisons?
The statement --theX
is using the pre-decrement operator. It decrements the value of the theX
before using it, so:
This:
if --theX > 0 {
}
is equivalent to:
theX -= 1
if theX > 0 {
}
The same is true for the others. If you were using a pre-decrement (--value
) or a pre-increment (++value
), then replace that with value -= 1
or value += 1
before using value
on the next line.
The problem with your translation of if --theX > 0
into if theX - 1 > 0
is that the value of theX
isn't being modified, so you'll use the wrong value for theX
when you construct the Point
in the return Point(x: theX, y: theY)
statement.
Related Topics
Nsdate() or Date() Shows the Wrong Time
Load a Uiview from Nib in Swift
What's the Difference Between "As", "As!", and "As"
Multiple Functions With the Same Name
Binary Operator * Cannot Be Applied to Operands of Type Int and Double
Failing Cast in Swift from Any? to Protocol
Swift - Iboutletcollection Equivalent
How to Create a Multi-Line Text Inside a Scrollview in Swiftui
How to See Which Version of Swift I'M Using
Overriding Methods in Swift Extensions
The "++" and "--" Operators Have Been Deprecated Xcode 7.3
Nsdate Timeintervalsince1970 Not Working in Swift
Swift Equality Operator on Nested Arrays
Removeobjectsatindexes For Swift Arrays
How to Declare a Variable That Has a Type and Implements a Protocol