inout generic struct parameter error


(Georgios Moschovitis) #1

From: Georgios Moschovitis <george.moschovitis@icloud.com>
Subject: Re: [swift-users] inout generic struct parameter error
Date: 1 January 2017 at 11:26:11 PM GMT+2
To: David Sweeris <davesweeris@mac.com>

This kinda works but because we pass a struct at:
the ‘garbage collection’ at:
doesn’t affect the original array.

The passed-in array isn't going to get modified though, because you never change it. At least semantically speaking, arrays in swift are pass-by-value, so when you assign it to your struct's local storage and then later modify the *struct's* variable, only the local copy gets affected. If you want to mutate the passed-in array, you'll have to do it in the function you pass it to.

That’s what I am trying to solve with the inout parameter. AFAICU if I use inout, I can mutate the original array (with the remove(at:) call in the iterator.

-g.

···

Begin forwarded message: