Download presentation
Presentation is loading. Please wait.
Published byIra Maximilian Jefferson Modified over 9 years ago
1
Monday, September 8, 2014 CSCI 351 – Mobile Applications Development
2
Swift – assignment Most operators in Swift behave similar to those of C or C++ let x = 7 var y = 10 y = x // assign statement does not return a value if y=x { // this produces an error in Swift println("Hi") } (m,n,p) = (2,3,9) // can use assignment with tuples
3
Swift – operators Arithmetic operators in Swift let a = 3 + 4.0 let b = 4.2 - 6 let c = 3 * -2 let d = 9 / 2 // integer division let e = 9 / 2.0 // floating point division let f = 13 % 5 let g = 11.5 % 4.5 // remainder works w floating point let h = "dog" + "house" // concatenation with strings let i = "O" + "K" // or characters let j = - a // unary minus
4
Swift – increment and decrement What will this code produce? var j = 5 var k = j++ var l = ++k j k l var m = 5 m *= 2
5
Swift – comparison operators The six comparison operators: ==, !=,, >= Ternary conditional operator: let score = 73 var grade = (score >= 70) ? "pass" : "fail" Compound operators: &&, ||, !
6
Swift – ranges A range from a to b is given by (a...b) for num in 3...7 { println("\(num) times 10 is \(num*10)") } Using a range to cycle through an array: let names = ["Anna", "Alex", "Brian", "Jack"] let numItems = names.count for m in 0...numItems-1 { println("Name \(m + 1) is called \(names[m])") }
7
Swift – characters and strings Unicode character set: http://unicode-table.comhttp://unicode-table.com A string literal: let today = "Monday" M String literals can include the following special characters: The escaped special characters \0 (null character), \\ (backslash), \t (horizontal tab), \n (line feed), \r (carriage return), \" (double quote) and \' (single quote) Single-byte Unicode scalars, written as \xnn, where nn is two hexadecimal digits Two-byte Unicode scalars, written as \unnnn, where nnnn is four hexadecimal digits Four-byte Unicode scalars, written as \Unnnnnnnn, where nnnnnnnn is eight hexadecimal digits
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.