[swift-users] super.init() called automatically?
James Campbell
james at supmenow.com
Tue May 17 05:24:45 CDT 2016
Not a big fan of this implict behaviour. Not super obvious.
*___________________________________*
*James⎥Head of Trolls*
*james at supmenow.com <james at supmenow.com>⎥supmenow.com <http://supmenow.com>*
*Sup*
*Runway East *
*10 Finsbury Square*
*London*
* EC2A 1AF *
On 17 May 2016 at 10:48, tuuranton--- via swift-users <swift-users at swift.org
> wrote:
> Why is this the intentional behavior? Seems a bit strange that init() is a
> special exception to the rule.
>
> 16. May 2016 19:29 by clattner at apple.com:
>
>
>
> On May 16, 2016, at 7:09 AM, tuuranton--- via swift-users <
> swift-users at swift.org> wrote:
>
> Why does the following code compile?
> Why does Bar's init(x: Int) automatically call Foo's init()?
> Why don't I have to manually call super.init() myself?
>
>
> This is intentional behavior. It kicks in when your super class has a
> single designated initializer with a zero-argument init. This is why you
> don’t have to call super.init() when deriving from NSObject.
>
> -Chris
>
>
> What passage of
>
> https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Initialization.html#//apple_ref/doc/uid/TP40014097-CH18-ID203
> tells me that this should be the case?
>
> --------------------
> class Foo {
> init() {
> print("foo init")
> }
> }
> class Bar: Foo {
> init(x: Int) {
> print("bar init")
> }
> }
> let b = Bar(x: 0)
> //prints:
> // bar init
> // foo init
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160517/418dbf9b/attachment.html>
More information about the swift-users
mailing list