gistlib
main.swiftlet str = "hello" var dict = [Character: Int]() for char in str { if let count = dict[char] { dict[char] = count + 1 } else { dict[char] = 1 } } print(dict) // Prints "["h": 1, "e": 1, "l": 2, "o": 1]" print(dict.count) // Prints "4" 264 chars14 lines
let str = "hello" var dict = [Character: Int]() for char in str { if let count = dict[char] { dict[char] = count + 1 } else { dict[char] = 1 } } print(dict) // Prints "["h": 1, "e": 1, "l": 2, "o": 1]" print(dict.count) // Prints "4"
Explanation:
dict
char
str
if let
gistlibby LogSnag