Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tomparkp committed Jan 15, 2015
0 parents commit a68a3b0
Show file tree
Hide file tree
Showing 564 changed files with 25,407 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added 1 - Prelude/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='3.0' sdk='iphonesimulator'>
<sections>
<code source-file-name='section-1.swift'/>
</sections>
<timeline fileName='timeline.xctimeline'/>
</playground>
37 changes: 37 additions & 0 deletions 1 - Prelude/1 - GettingStarted.playground/section-1.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

// Declaring Variables
var myVariable = "I can change" // -> No more semicolons (unless you want multiple statements on one line)

// Declaring Constants
let myConstant = "I'm constant"
// myConstant = "Try me" // -> Error: cannot reassign a constant

// Notice we aren't declaring a type -> Type Inference
// Try option + clicking a variable or constant to see its type

// Specifying a Type
let myString: String = "a string" // -> No Longer need @ prefix for strings
let myInteger: Int = 100
let myDouble: Double = 1.234
let myBool: Bool = true
let myArray: Array = ["string 1", "string 2"] // -> Infers contained types
let myIntArray: [Int] = [1, 2]
let myDictionary: Dictionary = ["key":"value"] // -> Infers contained types
let myIntDictionary: [Int:Int] = [1:2, 3:4]

// Variables and Constants in Swift cannot be nil
// var nilVariable = nil // -> Error: cannot be nil
// let nilConstant = nil

// String Interpolation
let stringWithVariable = "Look at me, \(myVariable)"

// Concatenate Strings
let twoStrings = "String 1 and " + "String 2"

// Logging
print(stringWithVariable)
println(twoStrings) // -> Adds a newline, more commonly used

// In Swift we access methods and properties with dot syntax
twoStrings.isEmpty
6 changes: 6 additions & 0 deletions 1 - Prelude/1 - GettingStarted.playground/timeline.xctimeline
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Timeline
version = "3.0">
<TimelineItems>
</TimelineItems>
</Timeline>
7 changes: 7 additions & 0 deletions 1 - Prelude/2 - Strings.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='3.0' sdk='iphonesimulator'>
<sections>
<code source-file-name='section-1.swift'/>
</sections>
<timeline fileName='timeline.xctimeline'/>
</playground>
16 changes: 16 additions & 0 deletions 1 - Prelude/2 - Strings.playground/section-1.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Playground - noun: a place where people can play

import UIKit

// We no longer need @
let string1 = "Game Over"
let string2 = " Man"
// We can concatenate strings easily
let combinedString = string1 + string2

var quote = "Game Over ".stringByAppendingString("Man")
quote += ", Game Over!"
println(quote.capitalizedString)

// String Interpolation
let interpolatedString = "\(combinedString), Game Over!"
6 changes: 6 additions & 0 deletions 1 - Prelude/2 - Strings.playground/timeline.xctimeline
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Timeline
version = "3.0">
<TimelineItems>
</TimelineItems>
</Timeline>
7 changes: 7 additions & 0 deletions 1 - Prelude/3 - Numerics.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='3.0' sdk='iphonesimulator'>
<sections>
<code source-file-name='section-1.swift'/>
</sections>
<timeline fileName='timeline.xctimeline'/>
</playground>
45 changes: 45 additions & 0 deletions 1 - Prelude/3 - Numerics.playground/section-1.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Playground - noun: a place where people can play

import UIKit

let crewMembers = 4 // Type Int
let lightyearsAway = 1.234 // Type Double

// Tip: Underscores can be used as thousands separator
let aMillionCredits = 1000000
let aCoolMillionCredits = 1_000_000

// Arithmetic
10 + 10 // Addition
10 - 10 // Subtraction
10 * 10 // Multiplication
10 / 10 // Division
10 % 10 // Remainder

// Numeric conversions must be explicit

let integer = 10
let double = 1.234

//let result = integer * double // Error: needs a type
let doubleResult = Double(integer) * double
let integerResult = integer * Int(double)

// Compound Operations
var compound = 10
compound += 10 // compound = compound + 10
compound -= 10
compound *= 10
compound /= 10
compound %= 10

// Unary Operations
var unary = 10

// Prefix
++unary
--unary

// Postfix
unary++
unary--
6 changes: 6 additions & 0 deletions 1 - Prelude/3 - Numerics.playground/timeline.xctimeline
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Timeline
version = "3.0">
<TimelineItems>
</TimelineItems>
</Timeline>
7 changes: 7 additions & 0 deletions 1 - Prelude/4 - Booleans.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='3.0' sdk='iphonesimulator'>
<sections>
<code source-file-name='section-1.swift'/>
</sections>
<timeline fileName='timeline.xctimeline'/>
</playground>
19 changes: 19 additions & 0 deletions 1 - Prelude/4 - Booleans.playground/section-1.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Playground - noun: a place where people can play

import UIKit

let theCake = false

// Only accepts true/false
let theCake = YES // Error
let theCake = TRUE // Error

// Only Booleans can be true/false
var myString = "The Cake is a Lie"
myString == true // Error
if myString {
// Error
}

var myInt = 1
myInt == true // Error
6 changes: 6 additions & 0 deletions 1 - Prelude/4 - Booleans.playground/timeline.xctimeline
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Timeline
version = "3.0">
<TimelineItems>
</TimelineItems>
</Timeline>
7 changes: 7 additions & 0 deletions 1 - Prelude/5 - Collections.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='3.0' sdk='iphonesimulator'>
<sections>
<code source-file-name='section-1.swift'/>
</sections>
<timeline fileName='timeline.xctimeline'/>
</playground>
37 changes: 37 additions & 0 deletions 1 - Prelude/5 - Collections.playground/section-1.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Playground - noun: a place where people can play

import UIKit

// Arrays
var characters = ["Luke Skywalker", "Anakin Skywalker"]
characters[1] = "Darth Vader"

// Easy concatenate
let moreCharacters = ["C3PO", "R2D2"]
characters += moreCharacters

// Methods
characters.append("Han Solo")
characters.insert("Princess Leia", atIndex: 0)
characters.removeAtIndex(1)

characters.count
characters.isEmpty
characters.first
characters.last

// Dictionaries
var professions = ["Boba Fett": "Bounty Hunter", "Han Solo": "Smuggler"]

// Access with key
professions["Han Solo"]

// Add with key
professions["Darth Vader"] = "Sith Lord"

// Methods
professions.removeValueForKey("Han Solo")
professions.updateValue("Boba Fett", forKey: "Sarlac Food")

professions.count
professions.isEmpty
6 changes: 6 additions & 0 deletions 1 - Prelude/5 - Collections.playground/timeline.xctimeline
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Timeline
version = "3.0">
<TimelineItems>
</TimelineItems>
</Timeline>
7 changes: 7 additions & 0 deletions 1 - Prelude/6 - ControlFlow.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='3.0' sdk='iphonesimulator'>
<sections>
<code source-file-name='section-1.swift'/>
</sections>
<timeline fileName='timeline.xctimeline'/>
</playground>
61 changes: 61 additions & 0 deletions 1 - Prelude/6 - ControlFlow.playground/section-1.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Playground - noun: a place where people can play

import UIKit

// Loops
for i in 1...3 {
println("O'doyle Rules")
}

var range = Range(start: 1, end: 4)

var i = 0
while i < 5 {
println("O'doyle Rules")
i++
}

let oceans = ["George Clooney", "Brad Pitt", "Matt Damon"]

for actor in oceans {
println(actor)
i++
}

// If/else
let enemyType = "Aliens"

if enemyType == "Wraith" {
println("Use Fire")
} else if enemyType == "Werewolf" {
println("Use Silver")
} else {
println("Nuke it from orbit")
}

// Comparison Operators
// == equal
// != not equal
// > greater than
// < less than
// >= greater or equal
// <= less or equal

// Logical Operators
// ! Not (invert)
// && And
// || Or

// Switches
let hero = "Thor"

switch hero {
case "Thor":
println("Asguard")
case "Iron Man", "Captain America":
println("New York, NY")
case "Hawkeye":
println("Waverly, Iowa")
default:
println("Unknown")
}
6 changes: 6 additions & 0 deletions 1 - Prelude/6 - ControlFlow.playground/timeline.xctimeline
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Timeline
version = "3.0">
<TimelineItems>
</TimelineItems>
</Timeline>
Binary file added 2 - Act I/.DS_Store
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit a68a3b0

Please sign in to comment.