[swift-evolution] [Proposal] Factory Initializers
Matthew Johnson
matthew at anandabits.com
Thu Dec 24 07:47:09 CST 2015
Sent from my iPad
> On Dec 23, 2015, at 11:57 PM, Charles Srstka via swift-evolution <swift-evolution at swift.org> wrote:
>
>> On Dec 23, 2015, at 11:09 PM, Riley Testut <rileytestut at gmail.com> wrote:
>>
>> Glad to see there's definitely some interest in this community then! I would love to start writing up a final proposal to submit to the Swift-Evolution repo, but I think that last piece of information needed would be the actual method of initialization, specifically should we allow for returning instances from convenience initializers, or should we simply assign to self?
>>
>> Personally, I think returning from the initializer makes the most sense, especially because "self" in a protocol extension seems ambiguous. However, I'm not that much in favor that I couldn't be convinced to simply assign to self, because that already has some low level support in the language. Anyone have strong thoughts one way or another?
>
> Assigning to self was always a bit weird. I think returning an instance makes more sense intuitively. It’s also, as you say, unclear exactly what “self” even means in the context of a protocol.
>
> Probably the way I’d do it would be to have the method declared “factory init” and be required to return an object.
+1 assuming we want to use the same syntax in type and protocol extensions. I don't like assign-to-self in a protocol extension.
Returning the instance also matches how factory methods are usually done in other languages. That shouldn't carry too much weight but it is worth noting.
>
> Charles
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151224/d6be6271/attachment.html>
More information about the swift-evolution
mailing list