I want to fill the dictionary with data, so that it looks like this: 1:Apple 2:Banana 3:Lemon
Sorry, if this is too simple for probably most of you - I am just a beginner. Anyway, here is the code:
var listOfFruit = ["Apple", "Banana","Lemon"]
var key = [1,2,3]
var dictionary = [Int: [String]]()
func createDictionary(){
for index in key {
dictionary[index] = []
var listOfFruit = ["Apple", "Banana","Lemon"]
for index1 in listOfFruit{
dictionary[index]?.append(index1)
}
}
}
print(dictionary)
The result of the above is "[:]\n" in my playground.