PHP programer here struggling with Swift. How do I create a Struct (Mutidimentional array in PHP) and walk through the elements to check a value?
Here is the code I am trying but it fails:
struct Alert: Codable {
let begin: Double
let end: Double
let color: String
let message: String
}
var alertStack = [ Int: Alert ]()
alertStack[60] = Alert(begin: 60.0,
end: 55.0,
color: "green",
message: "60 Seconds" )
alertStack[30] = Alert(begin: 30.0,
end: 25.0,
color: "yellow",
message: "30 Seconds!")
var alrtColor = "default" // Set default
var alrtText = "" // Set default
for alrt in alertStack {
if alrt.begin <= secondsLeft {
alrtColor = alrt.color // <-- Error
alrtText = alrt.message
}
}
Error is "Value of tuple type 'Dictionary<Int, Alert>.Element' (aka '(key: Int, value: Alert)') has no member 'begin'" For a PHP guy this error message is confusing. I tried a few other things but can't seem to get the result I am looking for. I am hoping there is a simple fix or example that would work.
alrtis(key: Int, value: Alert)so you get the properties from thevalue: ->alrt.value.begin