Skip to content

Commit 1cdcb30

Browse files
committed
Playground fixes
1 parent 28255e5 commit 1cdcb30

File tree

5 files changed

+52
-42
lines changed

5 files changed

+52
-42
lines changed

.DS_Store

0 Bytes
Binary file not shown.
Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2+
/*:
3+
4+
# Swift First Steps
5+
### Instructor: Timirah James
6+
7+
## Let's Dive Into Swift!
8+
9+
*/
10+
111
import UIKit
212

313
var str = "Hello, playground"
@@ -14,27 +24,19 @@ print("This should run properly")
1424

1525

1626

17-
18-
1927
// Declaring a Constant
2028

21-
let myFirstName:String = "Timirah"
22-
//myFirstName = "Tinashe"
29+
let myFirstName: String = "Timirah"
2330

24-
myFirstName
2531
myFirstName
2632

27-
myFirstName
28-
29-
3033
print(myFirstName)
3134

3235

3336

3437
//Declaring a Variable
3538

3639
var myAgeNow:Int = 23
37-
3840
var yourAgeNow:Int = 60
3941

4042
myAgeNow + yourAgeNow
@@ -43,10 +45,6 @@ myAgeNow + yourAgeNow
4345
//Syntax -- let/var keyword identifierName:DataType = value
4446

4547

46-
47-
48-
49-
5048
//Optionals
5149

5250
var userName: String? = "User1"
@@ -55,15 +53,13 @@ print(userName!)
5553

5654

5755
if userName != nil {
58-
print(userName! + " is a member")
56+
print(userName! + " is a member")
5957
}
60-
else {
61-
print("Guest user")
58+
else {
59+
print("Guest user")
6260
}
6361

6462

65-
66-
6763
//Implicitly Unwrapping
6864

6965
var username: String! = "User1"
@@ -76,27 +72,22 @@ var groceryList: [String] = ["eggs", "milk"]
7672
print(groceryList)
7773

7874

79-
8075
groceryList.append("juice")
81-
8276
groceryList.insert("bread", at: 2)
83-
8477
groceryList.count
8578

8679

8780

8881

89-
90-
9182
//Functions
9283

9384
func nameSports() {
94-
95-
let sport1 = "Basketball"
96-
let sport2 = "Baseball"
97-
let sport3 = "Golf"
98-
99-
print("Signing up for \(sport1), \(sport2), and \(sport3) this year.")
85+
86+
let sport1 = "Basketball"
87+
let sport2 = "Baseball"
88+
let sport3 = "Golf"
89+
90+
print("Signing up for \(sport1), \(sport2), and \(sport3) this year.")
10091
}
10192

10293
nameSports()
@@ -106,8 +97,8 @@ nameSports()
10697
//Functions with Parameters and Return Values
10798

10899
func createUser(name:String, age: Int){
109-
110-
print("New user: \(name) vs. \(age)")
100+
101+
print("New user: \(name) vs. \(age)")
111102
}
112103

113104

@@ -116,26 +107,45 @@ createUser(name: "Keisha", age: 11)
116107

117108
func getSum(firstNumber: Int, secondNumber: Int) -> Int{
118109

119-
//local parameters only
120-
return firstNumber + secondNumber
121-
110+
//local parameters only
111+
return firstNumber + secondNumber
112+
122113
}
123114

124115

125116
getSum(firstNumber: 25, secondNumber: 100)
126117
var x = getSum(firstNumber: 10, secondNumber: 80)
127118

128-
129119
x
130120

131121

132-
// Guard let
133-
134122

135-
//For and While Loops
123+
// if let
136124

125+
func greetStudent() {
126+
if let studentName = username {
127+
print(studentName + " is a member")
128+
}
129+
}
137130

138131

139-
//Dictionaries
140-
141-
132+
// guard let
133+
134+
/*
135+
func greetStudent() {
136+
guard let studentName = username else {
137+
return
138+
}
139+
*/
140+
141+
142+
143+
//Dictionaries (key-value pairings)
144+
var students = ["Name" : "Value"]
145+
146+
var capitols = ["California" : "Los Angeles", "Georgia" : "Atlanta", "Florida" : "Miami", "Texas" : "Austin"]
147+
148+
capitols["California"]
149+
150+
capitols["California"] = "LA"
151+
// Encodable / Decodable
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'>
2+
<playground version='5.0' target-platform='ios' display-mode='rendered'>
33
<timeline fileName='timeline.xctimeline'/>
44
</playground>

0 commit comments

Comments
 (0)