-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a68a3b0
Showing
564 changed files
with
25,407 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
7 changes: 7 additions & 0 deletions
7
1 - Prelude/1 - GettingStarted.playground/contents.xcplayground
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
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> |
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
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
6
1 - Prelude/1 - GettingStarted.playground/timeline.xctimeline
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
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> |
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
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> |
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
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!" |
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
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> |
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
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> |
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
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-- |
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
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> |
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
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> |
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
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 |
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
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> |
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
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> |
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
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 |
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
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> |
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
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> |
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
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") | ||
} |
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
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 not shown.
Binary file not shown.
Oops, something went wrong.