Upload
azilen-technologies
View
977
Download
1
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
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
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.
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
Why 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
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
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"
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?
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"])
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)")}
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."}
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
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)")}
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"} }
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"]
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)
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)}
ModernStructs
• Structs are similar to classes, but it excludes inheritance, deinitializers and reference counting.
struct normalStructure {func message(userName: String) -> String{return "Hello \(userName)"}}
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.
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.
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.
Is it a Right Time to Jump into Swift?
NO!
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?
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: