This document is an introduction to the Swift programming language presented by Dani Arnaout. It covers Swift data types, operators, strings, collection types, control flow, functions, and classes. The introduction includes examples to illustrate key concepts of the Swift syntax. It encourages readers to start coding in Swift and provides resources for learning more about the language.
26. 2 Swift Introduction to Swift
by Dani Arnaout
I. Data Types
var x = 3
var speedOfCar = 84.6
var orangesAreOrange = true
let maximumNumberOfSeasons = 4
27. var x = 3
var speedOfCar = 84.6
var orangesAreOrange = true
let maximumNumberOfSeasons = 4
2 Swift Introduction to Swift
by Dani Arnaout
I. Data Types
let beeseh = ""
let bobby = ""
28. 2. Basic Operators
2 Swift Introduction to Swift
by Dani Arnaout
unary: -a
binary: a+b
ternary: a?b:c
29. 3. Strings
2 Swift Introduction to Swift
by Dani Arnaout
var username = "Dani"
let uselessString = "This is a totally useless string"
30. 4. Collection Types
2 Swift Introduction to Swift
by Dani Arnaout
Array:
var shoppingList = ["Eggs", "Milk"]
var firstItem = shoppingList[0] // Eggs
Dictionary:
var userInfo = [“name”:”Dani", “age”:”24"]
var username = userInfo["name"] // Dani
31. 5. Control Flow
2 Swift Introduction to Swift
by Dani Arnaout
For:
for var i = 0; i < 3; i++ {
println("index is " + i)
}
For-in:
for i in 0...2 {
println("index is " + i)
}
// index is 0
// index is 1
// index is 2
// index is 0
// index is 1
// index is 2
32. 5. Control Flow
2 Swift Introduction to Swift
by Dani Arnaout
While:
var i = 0
while i < 3 {
println("index is ”+i)
i++
}
// index is 0
// index is 1
// index is 2
33. 5. Control Flow
2 Swift Introduction to Swift
by Dani Arnaout
If:
if temperatureInCelsius < 15 {
println("It's very cold. Consider wearing a scarf.")
} else {
println(“It's OK.”)
}
34. 5. Control Flow
2 Swift Introduction to Swift
by Dani Arnaout
Switch:
let temperatureInCelsius = 15
switch temperatureInCelsius {
case 15:
println(“Cold”)
default:
println(“Meh”)
}
35. 6. Functions
2 Swift Introduction to Swift
by Dani Arnaout
Define a function:
func sayHelloWorld() {
print(“Hello World”)
}
Call a function:
sayHelloWorld()
// Hello World
36. 6. Functions
2 Swift Introduction to Swift
by Dani Arnaout
Define a function:
func sayHelloWorld() -> String {
return “Hello World”
}
Call a function:
print(sayHelloWorld())
// Hello World
37. 6. Functions
2 Swift Introduction to Swift
by Dani Arnaout
Define a function:
func sayHello(personName:String) -> String {
return "Hello " + personName + "!"
}
Call a function:
print(sayHello("Dani"))
// Hello Dani!
38. 7. Classes
2 Swift Introduction to Swift
by Dani Arnaout
class Rectangle {
var width = 0
var height = 0
var hasBorders = false
var color : String?
}
48. Media Resources
• Personal pictures
• All Googled images are under usage right: Labeled for reuse
Web Resources
Software Used
5 Conclusion Introduction to Swift
by Dani Arnaout
Resources
• https://developer.apple.com/library/mac/documentation/Swift/Conceptual/Swift_Programming_Language
• http://raywenderlich.com
• https://github.com/raywenderlich/swift-style-guide
• Keynote (6.5)
• Xcode (6.1.1)
• Reflector (1.6.5)