[swift-evolution] Proposal: label-only constructors

Marc Knaup marc at knaup.koeln
Sun Dec 13 07:23:15 CST 2015


Using a static/class function would make subclassing difficult

   - you cannot hide them in subclasses (they're always inherited unlike
   initializers)
   - you can't call them from subclass initializers to properly initialize
   superclasses


On Sun, Dec 13, 2015 at 2:21 PM, Drew Crawford via swift-evolution <
swift-evolution at swift.org> wrote:

>
> On Dec 13, 2015, at 7:13 AM, ilya <ilya.nikokoshev at gmail.com> wrote:
>
> You can easily call a private parametrized init from a class function
> though.
>
>
> Sure, but we're just shuffling the deck.  We've gone from a bad public API
> to a bad private API.
>
> Actually, it's worse, because we now have BOTH a bad private API AND a bad
> public API.  There is a reason that NSData.dataWithData(...) is a Swift
> compile error.
>
> The (ab)use of class functions as constructors is a holdover from ObjC
> times.  If you want to make an instance in Swift, you should type
> ClassName( and see what autocomplete suggests; you should not have to read
> through the documentation of class functions to see if they are secretly
> constructors that have been filed at the wrong shelf in the library.
>
> _______________________________________________
> 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/20151213/beaec5c1/attachment.html>


More information about the swift-evolution mailing list