<div dir="ltr">Hi, <div><br></div><div>In Objective-C, I&#39;ve often attributed initializer from super classes as unavailable. Like this;</div><div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)"><span style="color:rgb(187,44,162)">@class</span><span style="color:rgb(0,0,0)"> </span><span style="">Dependency</span><span style="color:rgb(0,0,0)">;</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">@interface</span><span style=""> SomeClass : </span><span style="color:rgb(112,61,170)">NSObject</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span style="color:rgb(0,0,0)">- (</span><span style="">nullable</span><span style="color:rgb(0,0,0)"> </span><span style="">instancetype</span><span style="color:rgb(0,0,0)">)init </span><span style="color:rgb(120,73,42)">__unavailable</span><span style="color:rgb(0,0,0)">;</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">- (</span><span style="color:rgb(187,44,162)">nonnull</span><span style=""> </span><span style="color:rgb(187,44,162)">instancetype</span><span style="">)initWithDependency:(</span><span style="color:rgb(187,44,162)">nonnull</span><span style=""> </span><span style="color:rgb(112,61,170)">Dependency</span><span style=""> *)dependency;</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span style="">@end</span></p></div><div><span style=""><br></span></div><div>This makes the compiler complain if I try to instantiate <span style="font-family:Menlo;font-size:11px">[[</span><span style="font-family:Menlo;font-size:11px;color:rgb(112,61,170)">SomeClass</span><span style="font-family:Menlo;font-size:11px"> </span><span style="font-family:Menlo;font-size:11px;color:rgb(61,29,129)">alloc</span><span style="font-family:Menlo;font-size:11px">] </span><span style="font-family:Menlo;font-size:11px;color:rgb(61,29,129)">init</span><span style="font-family:Menlo;font-size:11px">];</span></div><div><br></div><div>However, If I declare a Swift class like this:</div><div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">class</span><span style=""> SomeClass: </span><span style="color:rgb(112,61,170)">NSObject</span><span style=""> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">    </span><span style="color:rgb(187,44,162)">init</span><span style="">(dependency: </span><span style="color:rgb(79,129,135)">Dependency</span><span style="">) {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">        </span><span style="color:rgb(187,44,162)">super</span><span style="">.</span><span style="color:rgb(187,44,162)">init</span><span style="">()</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">    }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">}</span></p></div><div><span style=""><br></span></div><div>The generated header file will look like this:</div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)"><br></span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">@interface</span><span style=""> SomeClass : </span><span style="color:rgb(112,61,170)">NSObject</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">- (</span><span style="color:rgb(187,44,162)">nonnull</span><span style=""> </span><span style="color:rgb(187,44,162)">instancetype</span><span style="">)initWithDependency:(</span><span style="color:rgb(112,61,170)">Dependency</span><span style=""> * </span><span style="color:rgb(187,44,162)">_Nonnull</span><span style="">)dependency </span><span style="color:rgb(120,73,42)">OBJC_DESIGNATED_INITIALIZER</span><span style="">;</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span style="">@end</span></p></div><div><span style=""><br></span></div><div>If I try to use init, it will be a run time error, and not a compile time error.</div><div>It there any way I can make Swift create the desired objc header file?</div><div><br></div><div><br></div><div>Svein Halvor</div><div><br></div></div>