I have this code very simple in kotlin which returns a value if a certain condition is satisfied, or null
val speed = location.speed.takeIf { it>=0 }
I'm trying to do the same in swift, but the only way I found is this:
let speed:Double?
if (location.speed>=0){
speed = location.speed
}else{
speed = nil
}
Is there any way more elegant?