<div dir="ltr"><div dir="ltr" class="gmail_msg">Ok, I understand. But my use case is adding functionality to obj-c class provided by the ios sdk through generics. As I see it's not something possible, I will go for an implementation that's it's not checking the type through generic at compile time.</div><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Wed, Dec 14, 2016 at 6:56 PM Jordan Rose <<a href="mailto:jordan_rose@apple.com" class="gmail_msg" target="_blank">jordan_rose@apple.com</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg">Right. Even though the class you want to expose isn't generic, its superclass is, and Objective-C needs to know the whole inheritance chain in order to use the class in any meaningful way.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Depending on what your use case is, you may be able to work with a @objc protocol instead (either imported or defined in Swift).</div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Jordan</div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On Dec 14, 2016, at 08:47, Charlie Monroe via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br class="m_1405668257712889126m_-35750649445137018Apple-interchange-newline gmail_msg"><div class="gmail_msg"><div style="word-wrap:break-word" class="gmail_msg">Hi Davide,<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">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="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">In ObjC, no matter what you use for the generics, you still have just 1 class that handles all call:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">@interface</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> MyClass<T> : </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="gmail_msg">NSObject</span></div><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo;color:rgb(186,45,162)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">@end</span></div></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo;color:rgb(186,45,162)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">@class</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> A, B;</span></div></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">NSLog(</span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b" class="gmail_msg">@"%@"</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">, NSStringFromClass([MyClass<A *> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">self</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">])); </span><span style="font-variant-ligatures:no-common-ligatures;color:#008400" class="gmail_msg">// MyClass</span></div><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">NSLog(</span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b" class="gmail_msg">@"%@"</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">, NSStringFromClass([MyClass<B *> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">self</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">])); </span><span style="font-variant-ligatures:no-common-ligatures;color:#008400" class="gmail_msg">// MyClass</span></div></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">[</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="gmail_msg">MyClass</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"><</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="gmail_msg">A</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> *> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">self</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">] == [</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="gmail_msg">MyClass</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"><</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="gmail_msg">B</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> *> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">self</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">]; </span><span style="font-variant-ligatures:no-common-ligatures;color:#008400" class="gmail_msg">// YES</span></div></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">In Swift, when you compile the generic class, a class is generated for each type you use - example:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">class</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> MyClass<T> {}</span></div><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">class</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> A {}</span></div><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">class</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> B {}</span></div><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo;min-height:10px" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"></span><br class="gmail_msg"></div><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo;color:rgb(62,30,129)" class="gmail_msg"><div style="margin:0px;line-height:normal;color:rgb(0,132,0)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81" class="gmail_msg">NSStringFromClass</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="gmail_msg">MyClass</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"><</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="gmail_msg">A</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">>.</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">self</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">) </span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">// _TtGC14__lldb_expr_417MyClassCS_1<b class="gmail_msg">A</b>_</span></div><div style="margin:0px;line-height:normal;color:rgb(0,132,0)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81" class="gmail_msg">NSStringFromClass</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="gmail_msg">MyClass</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"><</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="gmail_msg">B</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">>.</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">self</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">) </span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">// _TtGC14__lldb_expr_417MyClassCS_1<b class="gmail_msg">B</b>_</span></div></div></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">MyClass<</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="gmail_msg">A</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">>.</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">self</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> == MyClass<</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="gmail_msg">B</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">>.</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">self</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#008400" class="gmail_msg">// false</span></div></div><div style="margin:0px;font-size:9px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:#008400" class="gmail_msg"><br class="gmail_msg"></span></div><div class="gmail_msg">This makes what you suggest very complicated.</div><div class="gmail_msg"><br class="gmail_msg"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On Dec 14, 2016, at 2:47 PM, Davide Mendolia via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br class="m_1405668257712889126m_-35750649445137018Apple-interchange-newline gmail_msg"><div class="gmail_msg"><div dir="ltr" class="gmail_msg">Hi,<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Maybe this has been asked before but I couldn't find it.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I would like to be able to give visibility 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="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><p class="m_1405668257712889126m_-35750649445137018gmail-p1 gmail_msg"><span class="m_1405668257712889126m_-35750649445137018gmail-s1 gmail_msg"></span>Code Example:</p><p class="m_1405668257712889126m_-35750649445137018gmail-p2 gmail_msg"><span class="m_1405668257712889126m_-35750649445137018gmail-s1 gmail_msg">class</span><span class="m_1405668257712889126m_-35750649445137018gmail-s2 gmail_msg"> SwiftSuperType<T: NSObjectProtocol> : </span><span class="m_1405668257712889126m_-35750649445137018gmail-s3 gmail_msg">NSObject</span><span class="m_1405668257712889126m_-35750649445137018gmail-s2 gmail_msg"> {</span><br class="gmail_msg"></p></div><div class="gmail_msg"><p class="m_1405668257712889126m_-35750649445137018gmail-p1 gmail_msg"><span class="m_1405668257712889126m_-35750649445137018gmail-s2 gmail_msg">}</span></p><p class="m_1405668257712889126m_-35750649445137018gmail-p2 gmail_msg"><span class="m_1405668257712889126m_-35750649445137018gmail-s1 gmail_msg">class</span><span class="m_1405668257712889126m_-35750649445137018gmail-s2 gmail_msg"> NonGenericClass2: </span><span class="m_1405668257712889126m_-35750649445137018gmail-s4 gmail_msg">SwiftSuperType</span><span class="m_1405668257712889126m_-35750649445137018gmail-s2 gmail_msg"><</span><span class="m_1405668257712889126m_-35750649445137018gmail-s3 gmail_msg">NSObject</span><span class="m_1405668257712889126m_-35750649445137018gmail-s2 gmail_msg">> {</span><br class="gmail_msg"><span class="m_1405668257712889126m_-35750649445137018gmail-s2 gmail_msg"></span></p><div class="gmail_msg">
<br class="m_1405668257712889126m_-35750649445137018webkit-block-placeholder gmail_msg"></div><p class="m_1405668257712889126m_-35750649445137018gmail-p1 gmail_msg"><span class="m_1405668257712889126m_-35750649445137018gmail-s2 gmail_msg">}</span></p><p class="m_1405668257712889126m_-35750649445137018gmail-p1 gmail_msg"><span class="m_1405668257712889126m_-35750649445137018gmail-s2 gmail_msg">Or with a obj-c super class:</span></p><div class="gmail_msg"><p class="m_1405668257712889126m_-35750649445137018gmail-p2 gmail_msg"><span class="m_1405668257712889126m_-35750649445137018gmail-s2 gmail_msg">@interface</span><span class="m_1405668257712889126m_-35750649445137018gmail-s1 gmail_msg"> ObjcSuperType<T: </span><span class="m_1405668257712889126m_-35750649445137018gmail-s2 gmail_msg">id</span><span class="m_1405668257712889126m_-35750649445137018gmail-s1 gmail_msg"><NSObject>> : </span><span class="m_1405668257712889126m_-35750649445137018gmail-s3 gmail_msg">NSObject</span></p><p class="m_1405668257712889126m_-35750649445137018gmail-p3 gmail_msg"><span class="m_1405668257712889126m_-35750649445137018gmail-s1 gmail_msg">@end</span></p></div><div class="gmail_msg"><span class="m_1405668257712889126m_-35750649445137018gmail-s2 gmail_msg"></span><br class="m_1405668257712889126m_-35750649445137018webkit-block-placeholder gmail_msg"></div><div class="gmail_msg"><p class="m_1405668257712889126m_-35750649445137018gmail-p1 gmail_msg"><span class="m_1405668257712889126m_-35750649445137018gmail-s1 gmail_msg">class</span><span class="m_1405668257712889126m_-35750649445137018gmail-s2 gmail_msg"> NonGenericClass: </span><span class="m_1405668257712889126m_-35750649445137018gmail-s3 gmail_msg">ObjcSuperType</span><span class="m_1405668257712889126m_-35750649445137018gmail-s2 gmail_msg"><</span><span class="m_1405668257712889126m_-35750649445137018gmail-s4 gmail_msg">NSObject</span><span class="m_1405668257712889126m_-35750649445137018gmail-s2 gmail_msg">> {</span></p><p class="m_1405668257712889126m_-35750649445137018gmail-p1 gmail_msg"><span class="m_1405668257712889126m_-35750649445137018gmail-s2 gmail_msg">}</span></p></div><div class="gmail_msg"><span class="m_1405668257712889126m_-35750649445137018gmail-s2 gmail_msg"><br class="gmail_msg"></span></div><p class="m_1405668257712889126m_-35750649445137018gmail-p1 gmail_msg"><span class="m_1405668257712889126m_-35750649445137018gmail-s2 gmail_msg"><br class="gmail_msg"></span></p><p class="m_1405668257712889126m_-35750649445137018gmail-p1 gmail_msg"><span class="m_1405668257712889126m_-35750649445137018gmail-s2 gmail_msg">Actual Behaviour:</span></p><p class="m_1405668257712889126m_-35750649445137018gmail-p1 gmail_msg">Non-generic classes are not visible in obj-c. If adding the @objc notation we get the following error.</p><p class="m_1405668257712889126m_-35750649445137018gmail-p1 gmail_msg">Actual error message:<br class="gmail_msg"></p></div><div class="gmail_msg">Generic subclasses of '@objc' classes cannot have an explicit '@objc' attribute because they are not directly visible from Objective-C<br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">regards,</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">--</div><div class="gmail_msg">Davide Mendolia</div></div>
_______________________________________________<br class="gmail_msg">swift-evolution mailing list<br class="gmail_msg"><a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg"></div></blockquote></div><br class="gmail_msg"></div></div>_______________________________________________<br class="gmail_msg">swift-evolution mailing list<br class="gmail_msg"><a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg"></div></blockquote></div><br class="gmail_msg"></div></blockquote></div></div>