[swift-evolution] [Pitch] Improve `init(repeating:count)`
adrian.zubarev at devandartist.com
Thu Aug 17 04:38:48 CDT 2017
This is a small pitch which I will abandon if there is not much appetite for such improvement. ;)
I would like to propose an improvement to an initializer of all collection types that provide: init(repeating repeatedValue: Element, count: Int).
This change is meant to support reference type initialization on each iteration of the internal for-loop rather than copying the same references n times.
The change would be really straightforward and should not break existing code, except that the behavior would change for class types.
init(repeating repeatedValue: Element, count: Int)
let threeViews = Array(repeating: UIView(), count: 3) // contains 1 view 3 times
we would have:
init(repeating repeatedValue: @autoclosure () -> Element, count: Int)
This simple change would allow us to construct an array of different objects instead of an array with n references to the same object.
let threeViews = Array(repeating: UIView(), count: 3) // contains 3 different views
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution