Skip to content

Commit 105a648

Browse files
Gabrielle Miller-MessnerGabrielle Miller-Messner
authored andcommitted
Swift 2.0 edits to exercise files for Lesson 1 and Lesson 2
1 parent a6d7b2f commit 105a648

File tree

15 files changed

+46
-38
lines changed

15 files changed

+46
-38
lines changed

Lessons /Lesson1/Lesson1_Exercises.playground/Contents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let didYouKnowString = "Did you know that the Swift String class comes with lots
2020
let whisperString = "psst" + ", " + didYouKnowString.lowercaseString
2121
let shoutString = "HEY! DID YOU KNOW THAT THE SWIFT STRING CLASS COMES WITH LOTS OF USEFUL METHODS?"
2222
//: ### Exercise 3
23-
//: How many characters are in this string? Hint: One solution starts with casting the string as an array.
23+
//: How many characters are in this string?
2424
let howManyCharacters = "How much wood could a woodchuck chuck if a woodchuck could chuck wood?"
2525
//: ### Exercise 4
2626
//: How many times does the letter "g" or "G" appear in the following string? Use a for-in loop to find out!
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<playground version='5.0' target-platform='ios' display-mode='rendered'/>
2+
<playground version='5.0' target-platform='ios' requires-full-environment='true' display-mode='rendered'>
3+
<timeline fileName='timeline.xctimeline'/>
4+
</playground>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Timeline
3+
version = "3.0">
4+
<TimelineItems>
5+
</TimelineItems>
6+
</Timeline>

Lessons /Lesson2/Lesson2_DowncastingWithOptionals.playground/Contents.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ var drinkChoices = [
3737

3838
// Generic drink offer
3939
for beverage in drinkChoices {
40-
println ("Can I get you a \(beverage.category)")
40+
print ("Can I get you a \(beverage.category)")
4141
}
4242
//: Type cast operators: __as?__ and __as!__
4343
// Specific drink offer
4444
for beverage in drinkChoices {
4545
if let coldDrink = beverage as? ColdDrink {
46-
println ("Can I offer you a \(coldDrink.vessel) of \(coldDrink.category)?")
46+
print ("Can I offer you a \(coldDrink.vessel) of \(coldDrink.category)?")
4747
} else if let hotDrink = beverage as? HotDrink {
48-
println ("Can I get you some \(hotDrink.category) with \(hotDrink.pairing)?")
48+
print ("Can I get you some \(hotDrink.category) with \(hotDrink.pairing)?")
4949
}
5050
}
5151
//: ### Downcasting with as!
@@ -57,5 +57,5 @@ var coffeeArray: [Beverage] = [
5757

5858
for beverage in coffeeArray {
5959
let hotDrink = beverage as! HotDrink
60-
println ("Can I get you some \(hotDrink.category) with \(hotDrink.pairing)?")
60+
print ("Can I get you some \(hotDrink.category) with \(hotDrink.pairing)?")
6161
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<playground version='5.0' target-platform='ios' display-mode='rendered'>
2+
<playground version='5.0' target-platform='ios' requires-full-environment='true' display-mode='rendered'>
33
<timeline fileName='timeline.xctimeline'/>
44
</playground>

Lessons /Lesson2/Lesson2_Exercises.playground/Contents.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ class LoginViewController: UIViewController {
1818
}
1919

2020
//: ### Exercise 3
21-
//: The toInt() method of the Swift String class returns an optional of type Int?.
21+
//: The Swift Int type has an initializer that takes a string as a parameter and returns an optional of type Int?.
2222
//:
2323
//: 3a) Finish the code below by safely unwrapping the constant, `number`.
2424
var numericalString = "3"
25-
var number = numericalString.toInt()
25+
var number = Int(numericalString)
2626
//TODO: Unwrap number to make the following print statement more readable.
27-
println("\(number) is the magic number.")
27+
print("\(number) is the magic number.")
2828
//: 3b) Change the value of numericalString to "three" and execute the playground again.
2929

3030
//: ### Exercise 4
3131
//: The class UIViewController has a property called tabBarController. The tabBarController property is an optional of type UITabBarController?. The tabBarController itself holds a tabBar as a property. Complete the code below by filling in the appropriate use of optional chaining to access the tab bar property.
3232
var viewController = UIViewController()
3333
//if let tabBar = //TODO: Optional chaining here {
34-
// println("Here's the tab bar.")
34+
// print("Here's the tab bar.")
3535
//} else {
36-
// println("No tab bar controller found.")
36+
// print("No tab bar controller found.")
3737
//}
3838
//: ### Exercise 5
3939
//: Below is a dictionary of paintings and artists.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<playground version='5.0' target-platform='ios' display-mode='rendered'>
2+
<playground version='5.0' target-platform='ios' requires-full-environment='true' display-mode='rendered'>
33
<timeline fileName='timeline.xctimeline'/>
44
</playground>

0 commit comments

Comments
 (0)