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
Masy (26)

i mean i suggest xcode instead of repl for swift, it just works better, but it would still work to my understanding without nil