Latest Developments in Swift Programming
In our previous articles, we have explained, what Swift programming is, it’s features, and also the difference between Swift and Objective-C. We know the technology is growing at a faster rate, the developments are done at an exponential rate. In this article, we are going to talk about the latest developments in Swift programming language.
We know Swift 2.2 is almost here. It cleans up a number of quirks and added some missing features. So let us talk about the major and the minor changes in Swift so that you can run straight away to it.
THE DEVELOPMENTS IN SWIFT PROGRAMMING
++ and – – are deprecated
Swift 2.2 deprecates the ++ and – – operators, which means they still work but a user gets a warning message when he uses them. Deprecation is done for the first time towards removing something entirely, in this case, both of these operators will be removed in Swift 3.0.
In the place of ++ and –, a user needs to use += 1 and -= 1.
You might wonder why two long-standing operators has been removed, when they exist in C, C#, Java, and C++. There are several reasons for this question, but let’s see the major reasons for its removal.
* Writing ++ rather than += 1 is more time saving.
* ++ doesn’t have an obvious meaning to the people who are learning Swift, whereas += at least reads as “add and assign”.
Traditional C-style loops are deprecated
Loops like below will soon be removed from Swift.
for var i = 1; i <= 10; i += 1 {
print(“\(i) green bottles”)
}
These are called C-style loops. They have been from a very long time in languages like C. Although, Swift is a C-like language, it has a number of newer and smarter alternatives to replace this traditional loops.
To replace this traditional loops a user can use any one of the many alternatives. For instance, the above-written code can also be re-written to loop over a range, like this:
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for number in array {
print(“\(number) green bottles”)
Arrays and slice types now have removeFirst()
The removeLast() has been always helpful while working with arrays. Now we have the missing counterpart to remove the items from the beginning of the array. Swift 2.2 has introduced the new feature removeFirst() method. This removes the first element in an array and returns it to the user.
Renamed debug identifiers: #line, #function, and #file
Swift 2.1 earlier was using “snake case” symbols __File__, __Line__, __Column__, and __Function__, which automatically gets replaced by the compiler as the File name, Line number, Column number, and Function name when they appear.
Swift 2.1 earlier was using “snake case” symbols __File__, __Line__, __Column__, and __Function__, which automatically gets replaced by the compiler as the File name, Line number, Column number, and Function name when they appear.
VAR PARAMETERS HAVE BEEN DEPRECATED
Another deprecation in the list is, var parameters are deprecated because they offer only minimal usefulness.
func printGreeting(var name: String, repeat repeatCount: Int) {
name = name.uppercaseString
for _ in 0 ..< repeatCount {
print(name)
}
}
printGreeting(“Taylor”, repeat: 5)
Now the difference is, the name is now var name and name gets converted to uppercase so that “TAYLOR” will be printed out for five times.
Without the var keyword, the name would have been constant and the upper string line would be failed.