Skip to content

Instantly share code, notes, and snippets.

@dylankbuckley
Created September 18, 2016 19:05
Show Gist options
  • Save dylankbuckley/47b4a604e4b40925db6645d2c0f5a59c to your computer and use it in GitHub Desktop.
Save dylankbuckley/47b4a604e4b40925db6645d2c0f5a59c to your computer and use it in GitHub Desktop.
Learn Swift 3.0 & Xcode 8 (Part 1 - Swift Basics)
// Basic Operators
35 + 98
62 - 14
50 / 10
463 * 173
// Types
var age: Int = 21 // Int = Integer = Any whole number
var milesCanRun: Double = 0.75 // Double = Float = Decimal Number
var name: String = "Dylan" // String = Any Text = Quotation Marks
var awesome: Bool = true // Bool = Boolean = true / false
// Inferred Types
var dogsAge = 21
var dogsName = "Pluto"
var dogIsAwesome = true
var dogCanRunMiles = 10.5
// Variable Manipulation
dogsAge = 22
// Variable and Constant
let myFavouriteFood = "Chocolate"
// myFavouriteFood = "Apples" // Error
// Comparison Operators (<, >, ==, <=,...)
let myCurrentAge = 21
let myMumsAge = 45
let myFriendsAge = 23
let yearsOnEarth = 21
myCurrentAge > myMumsAge
myCurrentAge == yearsOnEarth
myCurrentAge < myMumsAge && myCurrentAge > myFriendsAge
myCurrentAge < myMumsAge || myCurrentAge > myFriendsAge
myCurrentAge >= yearsOnEarth
// If/Else Statements
if myCurrentAge < myMumsAge {
// I am older than my mum
print("I am younger than my mum")
} else {
// My mum is older than me
print("My mum is older than me")
}
// Basic Functions
func sayHello() {
print("Hello")
}
sayHello()
// Slightly more advanced function
let myName = "Dylan"
func sayHelloToMe(name: String) {
let helloString = "Hello \(name)"
print(helloString)
}
sayHelloToMe(name: myName)
// String Interpolation
let myNewName = "Steve"
let myNewAge = 60
let myAgeString = "\(myNewName) is \(myNewAge) years old"
@Hawkarali89
Copy link

thank you very helpful 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment