Skip to content

Commit f93546b

Browse files
committed
Fixed waring related to unwrapping optional value
1 parent 8d43548 commit f93546b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Data Structures.playground/Pages/Graph.xcplaygroundpage/Contents.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@ extension Edge: CustomStringConvertible, CustomDebugStringConvertible {
3333
}
3434

3535
private var commonDescription: String {
36-
return "from: \(from), \t to: \(to), \t weight: \(weight)"
36+
var weightDescription = ""
37+
38+
if let weight = self.weight {
39+
weightDescription = "\(weight)"
40+
} else {
41+
weightDescription = "nil"
42+
}
43+
44+
return "from: \(from), \t to: \(to), \t weight: \(weightDescription)"
3745
}
3846
}
3947

@@ -225,6 +233,6 @@ let results = adjacencyListGraph.searchVertex(with: "Moscow")
225233
print("\nSearch Results: ")
226234
print(results)
227235

228-
// Pleas note that the implementation is not complete. MST, Prim's and Dijkstra's algorithms will be added later.
236+
// Pleas note that the implementation is not complete. MST, Prim's and Dijkstra's algorithms will be added later.
229237

230238
//: [Next](@next)

0 commit comments

Comments
 (0)