+ 1

Handling user inputs

Started learning Swift and wanted to practice by solving code coach challenges, but I'm having troubles converting user inputs to arrays. https://code.sololearn.com/c3I42NMhIJvJ/?ref=app

22nd Jul 2020, 4:34 PM
Justus
Justus - avatar
3 Réponses
+ 1
in the second case, since you got the string from the user, you need to unwrap the value. Do it like word!.characters.split etc... add an ! aftet word and it works.
22nd Jul 2020, 5:51 PM
George Samanlian
+ 1
well, the user input can be nil. So swift wraps the input into an Optional String type and not String. In swift, every Optional String should be unwrapped either with an ? or an ! before being used to get the actual value. Unwrapping makes sure the value is not nil.
22nd Jul 2020, 6:18 PM
George Samanlian
0
George Samanlian thanks. Could you explain what unwrapping does
22nd Jul 2020, 6:05 PM
Justus
Justus - avatar