Swift 3.0 Released! Who Else Wants to Learn These New Features?

0
Shares
Swift 3.0 Released! Who Else Wants to Learn These New Features?
4 (80%) 1 vote

Swift3 features

Swift3 finally arrived on 13th September 2016.

And with it, major changes and new Swift features have been brought. We’ll highlight the most significant changes which will impact your code.

But, before we dive in, here is the fact.

Swift3 is available in Xcode 8 now which means developers can perform Swift migration to Swift3 on their own terms.

In this article, we’ll look at all the new features and provide every information about Swift programming language.

Swift Features:

When you converting modules to Swift3, you’ll notice that each file requires changes. It is because all the cocoa API names have been changed. The fact is, APIs are the same, but there is one name for Swift and one for objective C.

The Swift programming language (Swift3) book also outlines all new features implemented in Swift. Following are the new features implemented in Swift 3.

  • Function parameters have labels by default now.
  • The Attribute arguments use a colon.
  • Swift cases with multiple patterns have new functionality.
  • The line control statements now use the #SourceLocation syntax.

On top of these, the Autoclosures and Nonescaping closures have become type attribute rather than the declaration attributes.

Also, the parentheses now needed around the parameter types in the functions.

Welcoming Google To The Fray

Up Till now, we’ve heard many rumors about Google that it is preparing to drop its Java programming language for the Android app development in favor of Swift.

This indeed seems odd for the rivals like Apple and Google to share a base language as it would be a bold step. However, the Swift has already been the ‘Most loved’ programming language according to Stackoverflow’s 2015 survey, so it makes complete sense for Apple and Google to focus on promoting one programming language.

The Swift 3.0 Code Changes

Here, we’re sharing the code syntax changes that every developer must know for the Apple swift development.

import UIKit

import PlaygroundSupport

//++i i++ deprecated

//Old Tradition Addition way accepted in Swift 3

var i = 0

i += 1

//Old Tradition Substraction way accepted in Swift 3

var j = 0

j -= 1

//Various types of for-loops in Swift 3

//Simple for-in loop

for i in 1...10 {

  print(i)

}

//Simple for-each loop

(1...10).forEach {

  print($0)

}

var temp = [5, 6, 7, 8, 9, 10]

for val in temp{

    print(val)

}

//For-in reverse loops

for index in stride(from: 5, to: 1, by: -1) {

    print(index)

}

//prints 5, 4, 3, 2

for index in stride(from: 5, through: 1, by: -1) {

    print(index)

}

//prints 5, 4, 3, 2, 1

for (index, value) in temp.enumerated(){

    print("Index \(index) & value \(value)")

}

for index in (0..<temp.count).reversed(){

    print(temp[index])

}

//Various Ways to define Functions in Swift 3.0

//Simplest and most common way

func demo(_ a: Int, b: Int) -> Int{

    return a + b

}

//Function with mutating variable

func gcdDemo (a: Int) -> Int{

    let b = a

    return b + 5

}

//New Way to access Constants in Swift 3.0

//PI = 3.14

Double.pi

Float.pi

CGFloat.pi

//Getting File Path from the Project Folder

let file = Bundle.main.path(forResource: "tutorials", ofType: "json")

let url = URL(fileURLWithPath: file!)

let data = try! Data(contentsOf: url)

let json = try! JSONSerialization.jsonObject(with: data)

print(json)

//Types of Queue's

//Define Serial Queue

let queue = DispatchQueue(label: "Swift 3")

queue.async {

  print("Swift 3 queue")

}

//Define ConcurrentQueue

let concurrentQueue = DispatchQueue(label: "queuename", attributes: .concurrent)

concurrentQueue.sync {

    

}

//Define Main Thread queue async

DispatchQueue.main.async {

    

}

//Define Global Queue

DispatchQueue.global(qos: DispatchQoS.QoSClass.default).async {

    

}

DispatchQueue.global().async {

    // qos' default value is ´DispatchQoS.QoSClass.default`

}

//Array properties

//Array Ascending Sort

var numbers = [5, 6, 7, 8, 9, 10]

numbers.sort()

//Array Ascending Sort with Return

let arrNew = temp.sorted()

//Arrat Condtional Sort

temp.sort { (int1, int2) -> Bool in

    //UserCreationTime

    if int1 > int2{

        return true

    }

        

    //User Updation Time

    else if int1 < int2{

        return false

    }

    return false

}

Swift3 at WWDC 2016

Looking at the release notes of Swift 3.0, we’ve noticed many changes in the Swift programming language.

 

What’s New in Swift 3 : Highlights of WWDC 2016

  • Stabilizing The Binary Interface (ABI)

The Swift team at Apple is now looking forward developing a stable ABI that allows Swift to interact with various types of computers. However, this points to Swift is been ported to different systems.

  • Complete Generics

Swift use generics (algorithms) that are instantiated when required throughout its all libraries and the new Swift3 will complete the implementation.

  • Type System Cleanup and Documentation

The new Swift 3.0 programming language will revisit and document various subtyping and conversion rules. Also, their implementation will also be in the compiler’s type checker.

  • Focus and Refine The Swift3 Language

The Swift’s evolution document noted that Swift3’s rapid development has accumulated many library APIs and language features which don’t fit perfectly with the language as a whole. This means the Swift 3.0 will improve those features to offer better consistency for Swift programming language.

Bottom Line

All in all, whether you’re a technical person or not, you must know all these major changes and features of Swift 3. All these features can help you to develop a faster app than ever, and it could help you make your app interactional to your audience. Therefore, it is of utmost importance to hire Swift developer who can embrace all these features in your mobile app.

 
0
Shares
 

Want to Hire Swift Developers for Your Project? Contact us Now.