I have an array filled with structs. Let's say I want to change the first element of the array it if exists. I expected that something like this works:
if var first = &unconfirmedDataFromSocket.first {
first.markAsResend() // some mutating func
}
But I get this error:
Use of extraneous '&'
Is it possible in Swift to do what I want? Ofcourse there is an ugly workaround:
- Remove the
& - After calling markAsResend, remove the first element of the array and add the
firstvariable
But I was hoping for something more nicer.
if !unconfirmedDataFromSocket.isEmpty { unconfirmedDataFromSocket[0].markAsResend() }not as ugly.