I'm pretty much a beginner to swift. I am doing a lot of calculations with values that are intrinsically possibly not there, and I am constantly running into this pattern:
var lost : Double? = nil
if let original = original_value, let current = start_value {
lost = original - current
}
self.lost = lost
which works, but seems ridiculously more complex than it should be. I know I can go and define a minus between two optional doubles, which I will probably do, but I'm looking for a simplification for the generic case - is there generic way of doing essentially a x?.y operation across multiple variables - particularly I want to avoid having to have a variable which you assign twice. I was hoping you could do something like this:
self.lost = if let original = original_value, let current = start_value {original-current}
or this:
self.lost = (let original = original_value, let current = start_value ) ? original - current : nil
but it appears not - but I'm aiming for something like that