I am developing a app for ios and I am trying to get each letter of a member of dictionary which I have defined like this :
var Morse = ["a": "01", "b": "1000", "c": "1010", "d": "100", "e": "0", "f": "0010", "g": "110", "h": "0000", "i": "00", "j": "0111", "k": "101", "l": "0100", "m": "11", "n": "10", "o": "111", "p": "0110", "q": "1101", "r": "010", "s": "000", "t": "1", "u": "001", "v": "0001", "w": "011", "x": "1001", "y": "1011", "z": "1100", "1": "01111", "2": "00111", "3": "00011", "4": "00001", "5": "00000", "6": "10000", "7": "11000", "8": "11100", "9": "11110", "0": "11111", " ": "2"]
So for example, if the user enters a I would like to get "0" and then "1". To do this I use a counter :
var counter = 0
var letter: String = ""
var strings_letter: String = ""
letter = Morse[strings_letter]!
var number = Array(letter)[counter]
But this gives me an issue :
Argument type 'String' does not conform to expect type 'Sequence'
What am I doing wrong?
The
characters
property of aString
instance contains a sequence of the characters contained in theString
. You could, for a given key (say"a"
) re-map the.characters
of the corresponding value ("01"
) to single-characterString
instances to obtain aString
array: