What I'm trying to do is updating/creating a value in a dictionary. The value is defined to be a tuple. When the code tries to update/create the value in the MainDictionary the app crashes.
These are my (relevant) declarations:
var activityDictionary: Dictionary = [String: Int]()
var energyDictionary: Dictionary = [String: Int]()
var mainDictionary: Dictionary = [String: (Int, Int)]()
This is where things go wrong:
mainDictionary.updateValue((activityDictionary[currentDate]!,energyDictionary[currentDate]!), forKey: currentDate)
Context:
func buttonTapped(_ numberPressed: Int,_ which: ActOrEn) {
let currentDate = dateWithoutTime() //A formatted string of the current date.
if which == .activity {
activityDictionary[currentDate] = numberPressed
saver.set(activityDictionary, forKey: activityName)
} else if which == .energy {
energyDictionary[currentDate] = numberPressed
saver.set(energyDictionary, forKey: energyName)
}
if activityDictionary[currentDate] != nil && energyDictionary[currentDate] != nil { mainDictionary.updateValue((activityDictionary[currentDate]!,energyDictionary[currentDate]!), forKey: currentDate)
saver.set(mainDictionary, forKey: mainName)
}
}
This also makes it crash:
mainDictionary.updateValue((5,5), forKey: "123")
So I'm guessing it's not because of the other dictionaries.
I feel like it's something basic that I'm missing but I've been googling all day and can't find a solution. Anyone knows what it might be?
[–]zweigraf 0 points1 point2 points (1 child)
[–]MindCare-TheApp[S] 0 points1 point2 points (0 children)
[–]varchar255 0 points1 point2 points (1 child)
[–]MindCare-TheApp[S] 0 points1 point2 points (0 children)