Reputation: 61
This is my code:
var myTuple = ("bar", 42)
func foo(_ bar: inout (arg1: String, arg2: Double)) {
[...]
}
foo(&myTuple)
I get the following error for this line:
foo(&myTuple)
Cannot pass immutable value as inout argument: implicit conversion from '(String, Double)' to '(arg1: String, arg2: Double)' requires a temporary
Upvotes: 2
Views: 441
Reputation: 58029
The actual problem is that your tuple variable is missing labels that are present in the function. Replace it with the following:
var myTuple = (arg1: "bar", arg2: 42)
The problem is that an implicit conversion is required for a
(String, Int)
to match up with a(arg1: String, arg2: Int)
– by performing the implicit coercion, the compiler ends up with a temporary rvalue which cannot then be passed inout. That's why the error (somewhat confusingly) talks about an immutable value.
Upvotes: 3
Reputation: 3494
You have two options to do that
First: DO like that
var account3 = (name: "state bank personal", balance: 1000.00)
Or Second: Change method and use like that
func desposit0(amount:Double,account:inout (String,Double))->(String,Double)
use: account.0 and account.1
Upvotes: 0