In Swift, when you pass a value type, say an array for a function. A copy of the array is used for the function.
Although the documentation also says:
The above description refers to the "copy" of the strings, the arrays, and the behaviors you see in your code are always the same As if there was a copy. However, Swift only makes a real copy behind the curtain when it is absolutely necessary to do so. Swift manages copying all the prices to ensure optimal performance, and you should not avoid assignments to try to fulfill this optimization.
That's because the copy actually only takes when the passed value type has been modified?
Is there a way to demonstrate that this is actually the underlying behavior?
Why is this important? If I want to make a large irreversible array and pass it to function from function, I definitely do not want to make copies of it. Should I just use NSArrray in this case or will Swift Array work fine unless I try to manipulate to pass in the array?
Until now unless I explicitly make variables in editing the function by using the var or inhouse, the function can not modify the array in any way. So is it still a copy? It was assumed that another thread could modify the original array somewhere else (only when it is unstable), when making the function an essential copy (but only if the arrays have been passed) so that if the original array is irreversible And if the function is not using heroes or inside, then there is no point in copying in Swift. right? So what does Apple mean by the phrase above?
I do not know whether it is similar to every value type in Swift, but the array
s I'm pretty sure this is a copy-on-written, so it is not copied unless you modify it, and as you said you would pass it as continuous You do not run that risk anyway.
PS Swift 1.2 has new APIs that you can use to apply copy-on-written to your own value-types
Comments
Post a Comment