Created
September 18, 2016 19:05
-
-
Save dylankbuckley/47b4a604e4b40925db6645d2c0f5a59c to your computer and use it in GitHub Desktop.
Learn Swift 3.0 & Xcode 8 (Part 1 - Swift Basics)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you very helpful 👍