Apple Swift
New Programming Language for Mac & iOS Sen Ma
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
New Programming Language for Mac & iOS Sen Ma
Function patterns Concise syntax Native collections Operator overloading Namespaces Tuples Closures Protocols and extensions on structs Generics Clear mutability syntax Interactive playground Compile to native code Read-Eval-Print-Loop (REPL) Object orientation Type inference Optional Types Fast iteration Pattern matching Multiple return types
println("Hello World!") #include <iostream> using namespace std;
{ cout << "Hello World!" << endl; return 0; } "Hello World!"
goto pointers type casting uninitialized variables unsafe string formatting unclear copy / reference rules
var name: type = "value" var version: Double = 1.0 var year: Int = 2014 var LanguageName: String = "Swift"
let name: type = "value" let version: Double = 1.0 let year: Int = 2014 let LanguageName: String = "Swift"
let name: type = "value" let version: Double = 1.0 let year: Int = 2014 let LanguageName: String = "Swift"
let name = "value" let version = 1.0 let year = 2014 let LanguageName = "Swift"
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
let a=3, b=5 Output:
let a=3, b=5 println(a) println(b) Output:
let a=3, b=5 println(a) println(b) Output: 3 5
let a=3, b=5 println(a) println(b) Output: 3 5 3 times 5 is 8
let a=3, b=5 println(a) println(b) println("\(a) times \(b) is \(a*b)") Output: 3 5 3 times 5 is 8
for (var i=0; i<10; i++){ }
var i=0; while (i<10){ println(i) i++; }
for ch in "mouse"{ println(ch) } Output: m
u s e
for ch in "⿏鼡标"{ println(ch) } Output: ⿏鼡 标
for ch in "🐮🐮🐮🐮🐮"{ println(ch) } Output: 🐮 🐮 🐮 🐮 🐮
for num in 1…5{ println(num) } Output: 1 2 3 4 5
for num in 0..<5{ println(num) } Output: 0 1 2 3 4
let array = [1, 2, 3, 4, 5] Output:
let array = [1, 2, 3, 4, 5] println(array) Output:
let array = [1, 2, 3, 4, 5] println(array) Output: [1,2,3,4,5]
let array = [1, 2, 3, 4, 5] println(array) println(array[1]) Output: [1,2,3,4,5]
let array = [1, 2, 3, 4, 5] println(array) println(array[1]) Output: [1,2,3,4,5] 2
let array = [1, 2, 3, 4, 5] for num in array{ println(num) } Output: 1 2 3 4 5
func SayHello(){ println("Hello") } SayHello() Output:
func SayHello(){ println("Hello") } SayHello() Output: Hello
func SayHello(name: String){ println("Hello \(name)") } SayHello("Sen Ma") Output: Hello
func SayHello(name: String){ println("Hello \(name)") } SayHello("Sen Ma") Output: Hello Sen Ma
func SayHello(name: String)->String{ return "Hello " + name } SayHello("Sen Ma") Output: Hello Sen Ma