apple swift
play

Apple Swift New Programming Language for Mac & iOS Sen Ma - PowerPoint PPT Presentation

Apple Swift New Programming Language for Mac & iOS Sen Ma Function patterns Protocols and extensions on structs Fast iteration Closures Generics Concise syntax Pattern matching Native collections Optional Types Operator overloading


  1. Apple Swift New Programming Language for Mac & iOS Sen Ma

  2. Function patterns Protocols and extensions on structs Fast iteration Closures Generics Concise syntax Pattern matching Native collections Optional Types Operator overloading Object orientation Tuples Namespaces Type inference Clear mutability syntax Read-Eval-Print-Loop (REPL) Multiple return types Interactive playground Compile to native code

  3. Fast Modern Safe Interactive

  4. #include <iostream> using namespace std; � int main() { cout << "Hello World!" << endl; println("Hello World!") "Hello World!" return 0; }

  5. goto pointers type casting uninitialized variables unsafe string formatting unclear copy / reference rules

  6. Variables var name: type = "value" var version: Double = 1.0 var year: Int = 2014 var LanguageName: String = "Swift"

  7. Constant variables let name: type = "value" let version: Double = 1.0 let year: Int = 2014 let LanguageName: String = "Swift"

  8. Constant variables let name: type = "value" let version: Double = 1.0 let year: Int = 2014 let LanguageName: String = "Swift"

  9. Constant variables let name = "value" let version = 1.0 let year = 2014 let LanguageName = "Swift"

  10. Constant variables let name = "value" // Inference Type let version = 1.0 // Double let year = 2014 // Int let LanguageName = "Swift" // String let π = 3.1415926 // Double let 🐷 = "dog" // String

  11. println let a=3, b=5 
 Output: 


  12. println let a=3, b=5 
 println(a) 
 println(b) Output: 


  13. println let a=3, b=5 
 println(a) 
 println(b) Output: 
 3 
 5

  14. println let a=3, b=5 
 println(a) 
 println(b) Output: 
 3 
 5 
 3 times 5 is 8

  15. println let a=3, b=5 
 println(a) 
 println(b) 
 println("\(a) times \(b) is \(a*b)") Output: 
 3 
 5 
 3 times 5 is 8

  16. Demo

  17. Loops for (var i=0; i<10; i++){ } var i=0; while (i<10){ println(i) i++; }

  18. Loops - for in for ch in "mouse"{ println(ch) } Output: 
 m 
 o 
 u 
 s 
 e

  19. Loops - for in for ch in " ⿏鼡标 "{ println(ch) } Output: 
 ⿏鼡 
 标

  20. Loops - for in for ch in " 🐮🐮🐮🐮🐮 "{ println(ch) } Output: 
 🐮 
 🐮 
 🐮 
 🐮 
 🐮

  21. Loops - for in - Range for num in 1…5{ println(num) } Output: 
 1 
 2 
 3 
 4 
 5

  22. Loops - for in - Range for num in 0..<5{ println(num) } Output: 
 0 
 1 
 2 
 3 
 4

  23. Demo

  24. Array let array = [1, 2, 3, 4, 5] 
 Output: 


  25. 
 Array let array = [1, 2, 3, 4, 5] 
 println(array) 
 Output: 


  26. Array let array = [1, 2, 3, 4, 5] 
 println(array) 
 Output: 
 [1,2,3,4,5] 


  27. Array let array = [1, 2, 3, 4, 5] 
 println(array) 
 println(array[1]) Output: 
 [1,2,3,4,5] 


  28. Array let array = [1, 2, 3, 4, 5] 
 println(array) 
 println(array[1]) Output: 
 [1,2,3,4,5] 
 2

  29. Array let array = [1, 2, 3, 4, 5] 
 for num in array{ 
 println(num) 
 } Output: 
 1 
 2 
 3 
 4 
 5

  30. 
 Function func SayHello(){ 
 println("Hello") 
 } 
 SayHello() Output: 


  31. 
 Function func SayHello(){ 
 println("Hello") 
 } 
 SayHello() Output: 
 Hello

  32. 
 Function func SayHello(name: String){ 
 println("Hello \(name)") 
 } 
 SayHello("Sen Ma") Output: 
 Hello

  33. 
 Function func SayHello(name: String){ 
 println("Hello \(name)") 
 } 
 SayHello("Sen Ma") Output: 
 Hello Sen Ma

  34. 
 Function func SayHello(name: String)->String{ 
 return "Hello " + name 
 } 
 SayHello("Sen Ma") Output: 
 Hello Sen Ma

  35. Demo

Recommend


More recommend