[swift-users] Why does RangeReplaceableCollection require an empty initialiser?

Tim Vermeulen tvermeulen at me.com
Wed Jul 6 13:31:11 CDT 2016


I thought this was it, but none of the default implementations of RangeReplaceableCollection seem to use this empty initialiser (except for the two other initialisers and `removeAll(keepingCapacity:)`, the latter of which can be implemented using `removeSubrange(_:)` instead). This makes me wonder whether this is the right protocol to put an empty initialiser.

> On 6 Jul 2016, at 20:12, Tino Heth <2th at gmx.de> wrote:
> 
> Hi there,
> 
>> The requirement of the empty initialiser makes it impossible to have a collection conform to this protocol that needs additional data for its initialisation.
> But if there is no guarantee for an empty initializer, you always need a piece of data to create an instance — and when you do heavy "metaprogramming" (generics, protocols…), it can become very hard to supply this additional data.
> In those situations, it is very valuable when you can create an object out of thin air…
> 
> Tino



More information about the swift-users mailing list