<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 30, 2017, at 1:21 AM, Slava Pestov &lt;<a href="mailto:spestov@apple.com" class="">spestov@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Jan 30, 2017, at 1:12 AM, David Sweeris via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">So I’ve got this code in a package called “SomeLib":<blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">public</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">struct</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span>SomeType {</span></div></div><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">public</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">var</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span>text =<span class="Apple-converted-space">&nbsp;</span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"SomeText"</span></div></div><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;">}</div></div></blockquote><div class="">and then, in another package, write this:</div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">import</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span>SomeLib</span></div></div><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;">print(SomeType().text)</span></div></div></blockquote><div class="">and then run swift build, I get this error:</div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: 'Fira Mono';"><span class="" style="font-variant-ligatures: no-common-ligatures;">error: 'SomeType' initializer is inaccessible due to 'internal' protection level</span></div></div></blockquote><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">"Well that’s odd… there isn’t even an initializer to be internal or public”, I said to myself. Then I proceeded to futz around with it for a while before having a lightbulb moment:</span></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">public</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">struct</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span>SomeType {</span></div></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">public</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">var</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span>text =<span class="Apple-converted-space">&nbsp;</span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"SomeText"</span></div></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">public</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space">&nbsp;</span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">init</span><span class="" style="font-variant-ligatures: no-common-ligatures;">() {}<span class="Apple-converted-space">&nbsp;</span></span><span class="" style="font-variant-ligatures: no-common-ligatures;">//this fixes it</span></div></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;">}</span></div></span></div></blockquote><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;">In cases like this where the struct is public and all its stored properties are both public and already have values, should we make the implicit init() function also be public? Seems like the “least surprising” thing to do.</span></div></span></div></div></div></blockquote><div class=""><br class=""></div>This is intentional. I believe the core team’s rationale is that public APIs should always be explicitly written down in source. So your example above defining a public init() is correct.</div></div></blockquote></div><br class=""><div class="">Oh, I knew (well, suspected) it was intentional… I just didn't recall if we’d discussed this specific scenario before. If we did, then I don’t want to rehash it.</div><div class=""><br class=""></div><div class="">- Dave Sweeris</div></body></html>