What is new in Swift 3.0

Swift 3.0 is open-source and the major change released! The Swift 3.0 is huge major changes , improvement and refinement to the core language and Standard library. Swift 3.0 is the fast , safe and expressive.

Removing var from Function Parameters : the Var is removed from reference function parameters. now only passing the name and its type in Function of reference.

Before : 
func myiOSDev(var i : Int){
    print("MyValue === \(i)")
After 3.0/2.2:
func myiOSDev(i : Int){
    print("MyValue === \(i)")

Removing explicit use of let from Function Parameters : the let is removed from reference function parameters. Same as above function.
Before : 
func myiOSDev(let i : Int){
    print("MyValue === \(i)")
After 3.0/2.2: 
func myiOSDev(var i : Int){
    print("MyValue === \(i)")
Removing the ++ and -- operators : The Swift remove the incremental and Decremental operator. because of shorted form like += and -=. and second reason people is familiar with the shorten form extended (c++,Objective-C, java etc.) 

Before :
var myValue = 0
var incrementValue = myValue++
var decrementValue = myValue--
After 3.0: 
var myValue = 0
var incrementValue += myValue
var decrementValue -= myValue
Declare variables in 'Case' labels with multiple patterns :  Before you are not define multiple label pattern in single case. You have to define label individual in individual Case, But now Swift 3.0/Swift 2.2 you are define multiple label in single Case.

Switch with Multiple Case with Comma separator 
let day = "Sunday"
switch day {
  case "Sunday" , "Monday":
      print("Week Days")
Remove C-Style for-loops conditions and increment : The for loop with condition and increment or decrement is removed. Now only for-in loop is used in Swift.
Before :
for var index = 0 ; index < 10 ; index++ {
After :
for index in 1...10{
All function parameters have labels and  "_" with at first of function  : An underscore ( _ ) use before the first parameter , The caller won't use this parameter. 

Before :
override func viewWillAppear(animated: Bool)
override func didMoveToView(view: SKView)
func textFieldShouldReturn(textField: UITextField) -> Bool
After :
override func viewWillAppear(_ animated: Bool)
override func didMoveToView(_ view: SKView)
func textFieldShouldReturn(_ textField: UITextField) -> Bool
Drop NS prefix foundation Type : Remove the NS prefix in new swift. You can directly access without write NS prefix. for example : NSBundle now become Bundle, NSURL become URL in Swift 3.0

Before :
 let file = NSBundle.mainBundle().pathForResource("sun", ofType: "jpg")
 let url  = NSUL(fileURLWithPath: file!) let data = NSData(contentsOfURL: url)
After :
 let file = Bundle.mainBundle().pathForResource("sun", ofType: "jpg")
 let url =  URL(fileURLWithPath: file!) let data = Data(contentsOfURL: url)
Omit needless word  from function : Every word or function name have salient information in it. in Swift 3.0 all the salient word are removed.
Before : 
public mutating func removeElement(_ member: Element) -> Element?
Now :  As above function Element which is salient at call site. So removed from Swift function.
public mutating func remove(_ member: Element) -> Element?

More Examples : UIColor in which color is omit from suffix, maxElement in which Element is omit , UIDevice method of currentDevice in which Device is omit, and Array inset method in which Index is omit from atIndex.
Before :
let black = UIColor.blackColor()
let min = numbers.maxElement()
names.insert("Jane", atIndex: 0)
After :
let black = UIColor.black()
let min = numbers.max()
names.insert("Jane", at: 0)

Some of function renaming in swift 3.0 :

1 ) the generator is renamed to iterator across all APIs.
2) Memory is renamed to Pointee.
3)  sort() renamed as sorted()
4)  sortInPlace() 
renamed as sort()
5)  reverse() renamed as reversed()
6) enumerate() renamed as enumerated()

@discardableResult : This is used for when you don't want to use the return type value of the function. Before the function adding the @discardableResult,  its means the function is discardable. 
func myFullName(name : String) -> String{
    return name
Change uppercase notation to lowercase :

0)  .CGRect change cgRect.
1)  .System Changes .system
2)  .TouchUpInside change .touchUpInside
3)  .FillStroke change .fillStroke.
4)  .CGColor change .cgColor. 

Grand Central Dispatch : remove the boilerplate code.
Before Swift 2.2 :
let queue = dispatch_queue_create("Swift2.2", nil)
dispatch_async(queue) {
  print("Swift2.2 queue")
After Swift 3.0 :    
let queue = DispatchQueue(label: "Swift 3.0")
queue.async {
  print("Swift 3.0")

What is new in Swift 3.0 What is new in Swift 3.0 Reviewed by Kirit Modi on 03:34:00 Rating: 5

No comments:

Powered by Blogger.