<div dir="ltr"><div><div>That is not true. Structs can have delegating initializers but they cannot be marked with `convenience` (only the initializers of class types can).</div><div><br></div><div>This is very clear from both the documentation and the compiler:</div><div><br></div><div>(1) The Swift Programming language (Swift 4):</div><div><div>&quot;Swift defines two kinds of initializers for *class* types to help ensure all stored properties receive an initial value. These are known as designated initializers and convenience initializers.&quot;</div><div><br></div></div><div>(2) The compiler:</div><div><br></div><div>struct S {</div><div>    var a, b: Int</div><div>    init(_ a: Int, _ b: Int) {</div><div>        self.a = a</div><div>        self.b = b</div><div>    }</div><div>    convenience init(_ ab: Int) { // &lt;-- Error</div><div>        self.init(ab, ab)</div><div>    }</div><div>}</div><div>The error message is:<br></div><div>Delegating initializers in structs are not marked with &#39;convenience&#39;</div></div><div>The suggested fix is to remove the word convenience.</div><div><br></div>Please reread my previous post, perform the steps I describe (looking at Quick Help, also try jump to definition for that `init` and you&#39;ll see it is marked with `convenience` even though it is in a struct), also look at the link to the documentation for the Int init, it too is marked with convenience, even though Int is a struct.<div><br></div><div>/Jens</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jul 18, 2017 at 9:46 PM, Slava Pestov <span dir="ltr">&lt;<a href="mailto:spestov@apple.com" target="_blank">spestov@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi Jens,<div><br></div><div>While I’m not familiar with the integer API in the standard library, structs and enums certainly can have convenience initializers. They must delegate to another initializer (either convenience or designated) rather than initializing the fields of the type one by one.</div><div><br></div><div>Slava</div><div><br><div><blockquote type="cite"><div><div class="h5"><div>On Jul 18, 2017, at 6:46 AM, Jens Persson via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:</div><br class="m_1803250266694613670Apple-interchange-newline"></div></div><div><div><div class="h5"><div dir="ltr"><div>Start a command line project in Xcode 9 beta 3 and copy paste this single line of code into main.swift</div><div><br></div><div><div>let _ = UInt8.init(<wbr>extendingOrTruncating: UInt64(123456))</div></div><div><br></div><div>Now look at Quick Help while placing the cursor on `init` and then on `extendingOrTruncating`.</div><div><br></div><div>Note that (and how) the documentation for the initializer differs depending on where you place the cursor.</div><div><br></div><div>If the cursor is on `init`, the initializer is shown to be a convenience(!) initializer even though structs (such as UInt8) cannot have convenience initializers, right?</div><div><br></div><div>Even the official documentation for this and several other initializer like eg:</div><div><a href="https://developer.apple.com/documentation/swift/int/2885075-init" target="_blank">https://developer.apple.com/<wbr>documentation/swift/int/<wbr>2885075-init</a></div><div>clearly shows convenience initializers in structs.</div><div><br></div><div>By the way, .init(extendingOrTruncating:) doesn&#39;t show in the list of completions for &quot;UInt8.init&quot; but it does for &quot;UInt8(&quot;.</div><div><br></div><div><br></div><div>Can anyone explain what&#39;s going on?</div><div><br></div><div>Are these known issues that will go away in time for Xcode 9 GM?</div><div><br></div><div>/Jens</div><div><br></div></div></div></div>
______________________________<wbr>_________________<br>swift-users mailing list<br><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br></div></blockquote></div><br></div></div></blockquote></div><br></div>