Created
August 20, 2018 18:31
-
-
Save dmathewwws/21307cc2b434bb1aa6f7aa3bc71d83f8 to your computer and use it in GitHub Desktop.
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
//:> # Swift | |
//: | |
//: * Modern | |
//: * Objective-C Interoperability | |
//: * Open source | |
//: * Interactive Playgrounds | |
//: | |
//:> # Playgrounds | |
//: | |
//: * Live rendering of code you type | |
//: * Test pieces of code | |
//: * Good for education | |
//: | |
//: [Next](@next) | |
//variables and constants | |
//explicit types / type inference / Type conversions | |
//string interpolation | |
//simple optionals and unwrap them using if let, !, and ? | |
//mutable and immutable arrays | |
//if and switch | |
//loops with the for i in 0...n syntax | |
//functions that accept and return parameters | |
//Classes & Structs | |
//Enums | |
//Protocols + Extensions | |
let name = "Danny" | |
let age = 30 | |
print("\(name) \(age)") | |
let numberString = "Hello" | |
let numberAsInt = Int(numberString) | |
if let number = numberAsInt { | |
let addition = number + 30 | |
}else{ | |
print("What did you pass in!!!") | |
} | |
let fruits = ["apples", "pear", "pineapple"] | |
fruits[0] | |
for fruit in fruits { | |
let uppercase = fruit.uppercased() | |
print("The fruit is \(uppercase)") | |
} | |
for index in 0..<fruits.count { | |
let fruit = fruits[index] | |
let uppercase = fruit.uppercased() | |
print("The fruit is \(uppercase) at index \(index)") | |
} | |
let airports = [ | |
"YVR" : "Vancouver", | |
"YYC" : "Calgary" | |
] | |
let airportName = airports["YVR"] | |
if fruits.count > 3 { | |
print("inside a big fruits array") | |
}else if fruits.count < 5 { | |
}else{ | |
} | |
let fruit = fruits[0] | |
let answer = "apples" | |
switch fruit { | |
case "apples": | |
print("inside apples case") | |
case "apples2": | |
print("inside apple2 case") | |
case answer: | |
print("inside apple2 case") | |
default: | |
print("in default case") | |
} | |
func printHello(name:String) -> String { | |
return "Hello, \(name)" | |
} | |
let helloText = printHello(name: "Danny") | |
helloText | |
class Shape { | |
var sides:Int | |
init(sides:Int) { | |
self.sides = sides | |
} | |
} | |
let shape = Shape(sides: 9) | |
let shapeCopy = shape | |
shapeCopy.sides = 10 | |
print("shape's number of sides is \(shape.sides)") | |
print("shape's number of sides is \(shapeCopy.sides)") | |
struct ShapeStruct { | |
let sides:Int | |
} | |
let shapeStruct = ShapeStruct(sides: 9) | |
let shapeStructCopy = shapeStruct | |
print("shapeStruct's number of sides is \(shapeStruct.sides)") | |
print("shapeStructCopy's number of sides is \(shapeStructCopy.sides)") | |
enum Deck:String { | |
case spades = "s" | |
case hearts | |
case diamonds | |
func toPrettyString(){ | |
self.rawValue.uppercased() | |
} | |
} | |
extension String { | |
func prettyString(){ | |
} | |
} | |
var hello = "Hello" | |
hello.prettyString() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment