25
Developer’s Viewpoint on Swift Programming Language

Developer’s viewpoint on swift programming language

Embed Size (px)

DESCRIPTION

Swift is a modern programming language introduced by Apple. Let’s discus the functionality of Swift to understand why it is easy, modern and fast.

Citation preview

Page 1: Developer’s viewpoint on swift programming language

Developer’s Viewpoint on Swift Programming Language

Page 2: Developer’s viewpoint on swift programming language

Agenda

• Overview• Drawbacks of Objective-C• Why Swift?• Is it a Right Time to Jump into Swift?• Summary

Page 3: Developer’s viewpoint on swift programming language

Overview

• Chris Lattner, is the designer/creator/maker of Swift programming language. Previously who has built the powerful LLVM (Low Level Virtual Machine) compiler that Apple is using with XCode to build Objective-C programs.

• After the success of LLVM, Apple invests Chris for designing a new programming language Swift.

Page 4: Developer’s viewpoint on swift programming language

Drawbacks of Objective-C

In Objective-C,

• Need to Write more lines of code for the same functionality

• Memory Management is Difficult

• Can’t implement accurate automatic garbage collection in a language that has pointers

Page 5: Developer’s viewpoint on swift programming language

Why Swift Programming Language?

Page 6: Developer’s viewpoint on swift programming language

EasyConstants & Variables

Defining constants or variables is simple in Swift, use “let” to define constant and “var” to define variable.

let companyName = "XYZ"var stockPrice = 256

Page 7: Developer’s viewpoint on swift programming language

EasyType Inference

• Don’t require to specify the type with constants and variables.

• The Compiler automatically inferred it based on the value you have assigned.

let userName = "Eric" // inferred as Stringlet userAge = 28 // inferred as Int

Page 8: Developer’s viewpoint on swift programming language

EasyString Interpolation & Mutability

• include value in string using \() to concatenating string

let Points = 500let output = "Jimmy today you earned \(Points) points.“

• The simple way of string Mutability with swift

var message = "Good Morning" message += "Karan" // Output will be "Good Morning Karan"

Page 9: Developer’s viewpoint on swift programming language

EasyOptional Variable & Function Return Types

• You can define possibly missing or optional value in variables, so you don’t need to worry about nil value exception

var optionValue: Int?

• You can also make your function return type options

func getUserName(userId: Int) -> String?

Page 10: Developer’s viewpoint on swift programming language

EasyArray & Dictionary

• It's easier to work with Array & Dictionary

let usersArray = ["John","Duke","Panther","Larry"] // Arrayprintln(usersArray [0])let totalUsers = ["male":6, "female":5] // Dictionaryprintln(totalUsers["male"])

Page 11: Developer’s viewpoint on swift programming language

EasyFor-In: Ranges

• Just use .. to make range that exclude the upper value, or use … to include the upper value in the range.

for i in 0...3 {println("Index Value Is \(i)")}

Page 12: Developer’s viewpoint on swift programming language

ModernSwitch Cases

• Now it’s possible to compare any kind of data with Switches . You can also make conditions with Case statement.

let user = "John Deep"switch user {case "John":let output = "User name is John."case let x where x.hasSuffix("Deep"):let output = "Surname of user is \(x)."default:let vegetableComment = "User not found."}

Page 13: Developer’s viewpoint on swift programming language

ModernFunctions

• You can return multiple values from the function using tuple

func getUserList() -> (String,String,String){return ("John","Duke","Panther")}

• You can also pass variable number of arguments, collecting them Into an array

Page 14: Developer’s viewpoint on swift programming language

Modernfunc addition(values:Int...) -> Int{var total = 0for value in values {total += value}return total}

• You can set the default parameter value into a function

func sayHello(name: String = "Hiren"){println("Hello \(name)")}

Page 15: Developer’s viewpoint on swift programming language

Modern

Enumerations

• It’s providing multiple functionalities. Like classes, now you can also write methods

into enumerations:enum Section: Int {case First = 1case Second, Third, Fourthcase Fifthfunc Message() -> String {return "You are into wrong section"} }

Page 16: Developer’s viewpoint on swift programming language

ModernClosures

• You can write Closures without a name with braces ({})

var users = ["John","Duke","Panther","Larry"]users.sort({(a: String, b: String) -> Bool inreturn a < b})println(users)// Output = ["Duke", "John", "Larry", "Panther"]

Page 17: Developer’s viewpoint on swift programming language

ModernTuples

• Tuples enable you to create and pass groupings of values. Also, allow you to return multiple values as a single compound value.

(404, "Page Not Found", 10.5) // (Int, String, Double)

Page 18: Developer’s viewpoint on swift programming language

ModernGenerics

• You can make generics of any functions, classes or enumerations when you required variety of variable types.

enum jobType<T>{case Nonecase Some(T)}

Page 19: Developer’s viewpoint on swift programming language

ModernStructs

• Structs are similar to classes, but it excludes inheritance, deinitializers and reference counting.

struct normalStructure {func message(userName: String) -> String{return "Hello \(userName)"}}

Page 20: Developer’s viewpoint on swift programming language

FastAuto Memory Management

• ARC working more accurately with Swift.

• ARC track and manage your app memory usage, so you did not require managing memory yourself.

• ARC frees up your created objects when they are no longer needed.

• ARC automatically identify the object which you want to hold temporarily and which for long use by reference of every object.

Page 21: Developer’s viewpoint on swift programming language

FastLLVM Compiler

• The LLVM compiler converts Swift code into native code.

• Using LLVM, it's possible to run Swift code side-by-side with Objective-C.

• LLVM is currently the core technology of Apple developer tools; it helps to get the most out of iPhone, iPad and Mac hardware.

Page 22: Developer’s viewpoint on swift programming language

FastPlaygrounds

• Playgrounds make writing Swift code simple & fast.

• Playgrounds help you to view your variables into a graph, it directly displays output of your code, and you don't require to compile it every time.

• Playground is like a testing tool of your code. First check output of your code with playground, when you have perfected it, just move it into your project.

• Playground will be more useful when you are designing any new algorithm or experimenting with some new APIs.

Page 23: Developer’s viewpoint on swift programming language

Is it a Right Time to Jump into Swift?

NO!

Page 24: Developer’s viewpoint on swift programming language

Is it a Right Time to Jump into Swift?

• Swift & XCode-6 both is currently in a beta version.

• Many issues found in XCode-6, even in default templates of Swift. It will take 2-3 months for stable release.

• In iOS Application development, 3rd party libraries & frameworks are used which is in Objective-C. This will take time to convert into Swift, May be 2-3 months or more time!

• You will argue that Apple provided functionality to work Swift code side-by-side with Objective-C, but is it worth to develop application in Swift using Objective-C libraries?

Page 25: Developer’s viewpoint on swift programming language

Summary

Learning advanced & new things into IT field is defiantly a plus point. But when its used and applied with proper supports it will be more beneficial to you.

Follow Us: