<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Seems reasonable to me. It looks like&nbsp;<a href="https://bugs.swift.org/browse/SR-746" class="">SR-746</a>&nbsp;tracks the same thing. Patches welcome!</div><div class=""><br class=""></div><div class="">Jordan</div><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 8, 2016, at 7:06, Svein Halvor Halvorsen via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">This is even worse if I want to create a singleton, and ensure that the only way to access it, is through a static let on the class:<div class=""><br class=""></div><div class="">class Singleton: NSObject {</div><div class="">&nbsp; &nbsp; static let instance = Singleton()</div><div class="">&nbsp; &nbsp; private override init() {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; super.init()</div><div class="">&nbsp; &nbsp; }</div><div class="">}</div><div class=""><br class=""></div><div class="">In Swift, I can't instantiate this class, since it has no internal/public initializers. However, since it inherits from NSObject (which is necessary to access it from objc), I can initialize it from objc, even though it's private. Annotating it with @nonobjc doesn't help either.</div><div class=""><br class=""></div><div class="">Is there a reason why Swift doesn't automatically declare accessors from the super class, that are either private or @nonobjc in the Swift subclass implementation, as __unavailable?</div><div class=""><br class=""></div><div class="">Is there anyway I can enforce it using some (combination of) attributes?</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">sv.</div><div class=""><br class=""></div><div class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">2016-06-08 15:12 GMT+02:00 Svein Halvor Halvorsen <span dir="ltr" class="">&lt;<a href="mailto:svein.h@lvor.halvorsen.cc" target="_blank" class="">svein.h@lvor.halvorsen.cc</a>&gt;</span>:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">Hi,&nbsp;<div class=""><br class=""></div><div class="">In Objective-C, I've often attributed initializer from super classes as unavailable. Like this;</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span style="color:rgb(187,44,162)" class="">@class</span><span style="" class=""> </span><span class="">Dependency</span><span style="" class="">;</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="color:rgb(187,44,162)" class="">@interface</span><span class=""> SomeClass : </span><span style="color:rgb(112,61,170)" class="">NSObject</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="" class="">- (</span><span class="">nullable</span><span style="" class=""> </span><span class="">instancetype</span><span style="" class="">)init </span><span style="color:rgb(120,73,42)" class="">__unavailable</span><span style="" class="">;</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="">- (</span><span style="color:rgb(187,44,162)" class="">nonnull</span><span class=""> </span><span style="color:rgb(187,44,162)" class="">instancetype</span><span class="">)initWithDependency:(</span><span style="color:rgb(187,44,162)" class="">nonnull</span><span class=""> </span><span style="color:rgb(112,61,170)" class="">Dependency</span><span class=""> *)dependency;</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span class="">@end</span></div></div><div class=""><span class=""><br class=""></span></div><div class="">This makes the compiler complain if I try to instantiate&nbsp;<span style="font-family:Menlo;font-size:11px" class="">[[</span><span style="font-family:Menlo;font-size:11px;color:rgb(112,61,170)" class="">SomeClass</span><span style="font-family:Menlo;font-size:11px" class=""> </span><span style="font-family:Menlo;font-size:11px;color:rgb(61,29,129)" class="">alloc</span><span style="font-family:Menlo;font-size:11px" class="">] </span><span style="font-family:Menlo;font-size:11px;color:rgb(61,29,129)" class="">init</span><span style="font-family:Menlo;font-size:11px" class="">];</span></div><div class=""><br class=""></div><div class="">However, If I declare a Swift class like this:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="color:rgb(187,44,162)" class="">class</span><span class=""> SomeClass: </span><span style="color:rgb(112,61,170)" class="">NSObject</span><span class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="">&nbsp; &nbsp; </span><span style="color:rgb(187,44,162)" class="">init</span><span class="">(dependency: </span><span style="color:rgb(79,129,135)" class="">Dependency</span><span class="">) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:rgb(187,44,162)" class="">super</span><span class="">.</span><span style="color:rgb(187,44,162)" class="">init</span><span class="">()</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="">}</span></div></div><div class=""><span class=""><br class=""></span></div><div class="">The generated header file will look like this:</div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="color:rgb(187,44,162)" class=""><br class=""></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="color:rgb(187,44,162)" class="">@interface</span><span class=""> SomeClass : </span><span style="color:rgb(112,61,170)" class="">NSObject</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="">- (</span><span style="color:rgb(187,44,162)" class="">nonnull</span><span class=""> </span><span style="color:rgb(187,44,162)" class="">instancetype</span><span class="">)initWithDependency:(</span><span style="color:rgb(112,61,170)" class="">Dependency</span><span class=""> * </span><span style="color:rgb(187,44,162)" class="">_Nonnull</span><span class="">)dependency </span><span style="color:rgb(120,73,42)" class="">OBJC_DESIGNATED_INITIALIZER</span><span class="">;</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span class="">@end</span></div></div><div class=""><span class=""><br class=""></span></div><div class="">If I try to use init, it will be a run time error, and not a compile time error.</div><div class="">It there any way I can make Swift create the desired objc header file?</div><span class="HOEnZb"><font color="#888888" class=""><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Svein Halvor</div><div class=""><br class=""></div></font></span></div>
</blockquote></div><br class=""></div>
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></body></html>