Help Swift dictionaries problem. Cant figure out the nil issue.
dschwinne (0)

Using the dictionary given to you, loop through each person in your dictionary printing our their name and favorite sport.

Ex. "Doug's favorite sport is Baseball."

Provide a default value of "Track" to students who may not have a favorite sport. You can do this by using nil-coalescing.

As far as I have got....

//this was provided
var studentsFavoriteSports: [String : String?] = ["Doug" : "Baseball", "Patrick" : "Basketball", "Beverly" : nil, "Savannah" : "Soccer", "Billy": "Bowling", "Sean" : nil]

//this is my work
studentsFavoriteSports.removeValue(forKey: nil!)

for (name, favSport) in studentsFavoriteSports {
print("(name)'s favorite sport is (favSport)")

I am very very new so keep that in mind. I am just starting to learn to code.

You are viewing a single comment. View All
dschwinne (0)

I have been trying to remove nil, or to replace nil. Have not been able to do either due to it a string error.

Tried to create an else statement to replace it, and that won't work either.

Sorry for such a noob question.