<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="">Hi Davide,<div class=""><br class=""></div><div class="">AFAIK this is not (easily) possible (please, correct me someone if I'm wrong) since Swift's generics aren't "lightweight" as ObjC generics are.</div><div class=""><br class=""></div><div class="">In ObjC, no matter what you use for the generics, you still have just 1 class that handles all call:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">@interface</span><span style="font-variant-ligatures: no-common-ligatures" class=""> MyClass&lt;T&gt; : </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">NSObject</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">@end</span></div></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">@class</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> A, B;</span></div></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">NSLog(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">@"%@"</span><span style="font-variant-ligatures: no-common-ligatures" class="">, NSStringFromClass([MyClass&lt;A *&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">])); </span><span style="font-variant-ligatures: no-common-ligatures; color: #008400" class="">// MyClass</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">NSLog(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">@"%@"</span><span style="font-variant-ligatures: no-common-ligatures" class="">, NSStringFromClass([MyClass&lt;B *&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">])); </span><span style="font-variant-ligatures: no-common-ligatures; color: #008400" class="">// MyClass</span></div></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">[</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">MyClass</span><span style="font-variant-ligatures: no-common-ligatures" class="">&lt;</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">A</span><span style="font-variant-ligatures: no-common-ligatures" class=""> *&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">] == [</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">MyClass</span><span style="font-variant-ligatures: no-common-ligatures" class="">&lt;</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">B</span><span style="font-variant-ligatures: no-common-ligatures" class=""> *&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">]; </span><span style="font-variant-ligatures: no-common-ligatures; color: #008400" class="">// YES</span></div></div><div class=""><br class=""></div><div class="">In Swift, when you compile the generic class, a class is generated for each type you use - example:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">class</span><span style="font-variant-ligatures: no-common-ligatures" class=""> MyClass&lt;T&gt; {}</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">class</span><span style="font-variant-ligatures: no-common-ligatures" class=""> A {}</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">class</span><span style="font-variant-ligatures: no-common-ligatures" class=""> B {}</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; min-height: 10px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129);" class=""><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">NSStringFromClass</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">MyClass</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&lt;</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">A</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&gt;.</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">) </span><span style="font-variant-ligatures: no-common-ligatures" class="">// _TtGC14__lldb_expr_417MyClassCS_1<b class="">A</b>_</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">NSStringFromClass</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">MyClass</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&lt;</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">B</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&gt;.</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">) </span><span style="font-variant-ligatures: no-common-ligatures" class="">// _TtGC14__lldb_expr_417MyClassCS_1<b class="">B</b>_</span></div></div></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">MyClass&lt;</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">A</span><span style="font-variant-ligatures: no-common-ligatures" class="">&gt;.</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class=""> == MyClass&lt;</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">B</span><span style="font-variant-ligatures: no-common-ligatures" class="">&gt;.</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #008400" class="">// false</span></div></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #008400" class=""><br class=""></span></div><div class="">This makes what you suggest very complicated.</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 14, 2016, at 2:47 PM, Davide Mendolia 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 dir="ltr" class="">Hi,<div class=""><br class=""></div><div class="">Maybe this has been asked before but I couldn't find it.</div><div class=""><br class=""></div><div class="">I would like to be able&nbsp;to give visibility&nbsp;of non-generic subclass of a generic class to obj-c. Is there any limitation of the compiler knowing that the type of the non-generic type is closed, to generate a compatible version for obj-c?</div><div class=""><br class=""></div><div class=""><p class="gmail-p1"><span class="gmail-s1"></span>Code Example:</p><p class="gmail-p2"><span class="gmail-s1">class</span><span class="gmail-s2"> SwiftSuperType&lt;T: NSObjectProtocol&gt; : </span><span class="gmail-s3">NSObject</span><span class="gmail-s2"> {</span><br class=""></p></div><div class=""><p class="gmail-p1"><span class="gmail-s2">}</span></p><p class="gmail-p2"><span class="gmail-s1">class</span><span class="gmail-s2"> NonGenericClass2: </span><span class="gmail-s4">SwiftSuperType</span><span class="gmail-s2">&lt;</span><span class="gmail-s3">NSObject</span><span class="gmail-s2">&gt; {</span><br class=""><span class="gmail-s2"></span></p><div class="">











<br class="webkit-block-placeholder"></div><p class="gmail-p1"><span class="gmail-s2">}</span></p><p class="gmail-p1"><span class="gmail-s2">Or with a obj-c super class:</span></p><div class=""><p class="gmail-p2"><span class="gmail-s2">@interface</span><span class="gmail-s1">&nbsp;ObjcSuperType&lt;T:&nbsp;</span><span class="gmail-s2">id</span><span class="gmail-s1">&lt;NSObject&gt;&gt; :&nbsp;</span><span class="gmail-s3">NSObject</span></p><p class="gmail-p3"><span class="gmail-s1">@end</span></p></div><div class=""><span class="gmail-s2"></span><br class="webkit-block-placeholder"></div><div class=""><p class="gmail-p1"><span class="gmail-s1">class</span><span class="gmail-s2">&nbsp;NonGenericClass:&nbsp;</span><span class="gmail-s3">ObjcSuperType</span><span class="gmail-s2">&lt;</span><span class="gmail-s4">NSObject</span><span class="gmail-s2">&gt; {</span></p><p class="gmail-p1"><span class="gmail-s2">}</span></p></div><div class=""><span class="gmail-s2"><br class=""></span></div><p class="gmail-p1"><span class="gmail-s2"><br class=""></span></p><p class="gmail-p1"><span class="gmail-s2">Actual Behaviour:</span></p><p class="gmail-p1">Non-generic classes are not visible in obj-c. If adding the @objc notation we get the following error.</p><p class="gmail-p1">Actual error message:<br class=""></p></div><div class="">Generic subclasses of '@objc' classes cannot have an explicit '@objc' attribute because they are not directly visible from Objective-C<br class=""></div><div class=""><br class=""></div><div class="">regards,</div><div class=""><br class=""></div><div class="">--</div><div class="">Davide Mendolia</div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>