I am attempting to make a morse code converter in a Swift 3 playground. The function I am using does not successfully initiate the translation process, saying "Type 'String.CharacterView.IndexDistance' (aka 'Int') does not conform to protocol 'Sequence'".
func convertStringToMorse(_ input: String) -> String {
let stringToConvert = input
var charsInString = input.characters.count
var returnString = ""
for char in charsInString {
let returnChar = convertLetterToMorse(char)
if returnChar != "" {
returnString += returnChar + " "
}
}
return returnString
}
The error happens in the for char in charsInString
line, specifically at charsInString
. How do I fix this?