[swift-users] Fwd: inout generic struct parameter error

Georgios Moschovitis george.moschovitis at icloud.com
Sun Jan 1 15:29:34 CST 2017



> Begin forwarded message:
> 
> From: Georgios Moschovitis <george.moschovitis at 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 at 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.
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170101/41bcfdf8/attachment.html>


More information about the swift-users mailing list