CMPE277_Lec7_iOS_intro2swift.pdf

CMPE277_Lec7_iOS_intro2swift.pdf - A swift intro to Swift...

Info icon This preview shows pages 1–15. Sign up to view the full content.

A swift intro to Swift
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

What is Swift?
Image of page 2
What is Swift, seriously? General-purpose, multi-paradigm, compiled programming language Can be used for iOS, OS X, watchOS, tvOS, and Linux Safer and more concise than Objective-C (programming_language)
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Hello World OK, let’s make a fancier version var str="Hello, world!" println(str); func sayHello(){ println( "Hello, bebop!") } sayHello() Wow, it looks like JavaScript Acutually, it resembles more
Image of page 4
Swift and Groovy Source: What are the differences?
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Mix and Match! “Straightforward mix of features from Groovy, Scala, Java, C#, etc” the getter / setter syntax close to the one from C# the type after variable named and colon, like in Pascal -derived languages string interpolation like in many scripting languages, using \(foo) versus Groovy 's ${foo} the question mark suffix after a type to denote it can be nullable, like in Ceylon the range operators .. and ... borrowed from Ruby Source: Hybrid’s genetic advantage! Great for programmers, if done right
Image of page 6
Literals, Variables and Constants Automatic type inference Why not put the type at the beginning? int year = 2014 Why let and not const ? var version = 1.0 var year: Int = 2014 var service: String = “Job Search” var isExipred: Bool = false let brand = “Google Hire” let price : Double = 9.99 // USD
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.