Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Developer’s viewpoint on swift programming language


Published on

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.

Published in: Technology
  • Programming Swift: Create A Fully Function App: Learn In A Day! ---
    Are you sure you want to  Yes  No
    Your message goes here
  • Protocol Oriented Programming with Swift ---
    Are you sure you want to  Yes  No
    Your message goes here
  • Swift Programming: The Big Nerd Ranch Guide (Big Nerd Ranch Guides) ---
    Are you sure you want to  Yes  No
    Your message goes here

Developer’s viewpoint on swift programming language

  1. 1. Developer’s Viewpoint on Swift Programming Language
  2. 2. Agenda • Overview • Requirement of New Programming Language • Why Swift? • Is it a Right Time to Jump into Swift? • Summary
  3. 3. 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.
  4. 4. 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
  5. 5. Why Swift Programming Language?
  6. 6. Easy Constants & 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
  7. 7. Easy Type 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 String let userAge = 28 // inferred as Int
  8. 8. Easy String Interpolation & Mutability • include value in string using () to concatenating string let Points = 500 let 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"
  9. 9. Easy Optional 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?
  10. 10. Easy Array & Dictionary • It's easier to work with Array & Dictionary let usersArray = ["John","Duke","Panther","Larry"] // Array println(usersArray [0]) let totalUsers = ["male":6, "female":5] // Dictionary println(totalUsers["male"])
  11. 11. Easy For-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)") }
  12. 12. Modern Switch 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."}
  13. 13. Modern Functions • 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
  14. 14. Modern func addition(values:Int...) -> Int{ var total = 0 for 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)") }
  15. 15. Modern Enumerations • It’s providing multiple functionalities. Like classes, now you can also write methods into enumerations: enum Section: Int { case First = 1 case Second, Third, Fourth case Fifth func Message() -> String { return "You are into wrong section" } }
  16. 16. Modern Closures • You can write Closures without a name with braces ({}) var users = ["John","Duke","Panther","Larry"] users.sort({(a: String, b: String) -> Bool in return a < b }) println(users) // Output = ["Duke", "John", "Larry", "Panther"]
  17. 17. Modern Tuples • 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)
  18. 18. Modern Generics • You can make generics of any functions, classes or enumerations when you required variety of variable types. enum jobType<T>{ case None case Some(T) }
  19. 19. Modern Structs • Structs are similar to classes, but it excludes inheritance, deinitializers and reference counting. struct normalStructure { func message(userName: String) -> String{ return "Hello (userName)" } }
  20. 20. Fast Auto 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.
  21. 21. Fast LLVM 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.
  22. 22. Fast Playgrounds • 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.
  23. 23. Is it a Right Time to Jump into Swift? NO!
  24. 24. 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?
  25. 25. 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: