[swift-users] Any reason of "@objc is not supported within extensions of generic classes." ?

Zhao Xin owenzx at gmail.com
Wed Aug 24 21:34:28 CDT 2016


Thank you, Jordan.

Zhaoxin

On Thu, Aug 25, 2016 at 1:15 AM, Jordan Rose <jordan_rose at apple.com> wrote:

> The way @objc methods are added in an extension is by using Objective-C
> categories. With a generic class, though, there's no Class object to attach
> the category metadata to—it's all created dynamically at runtime.
>
> We could potentially support this some day, but it would take some
> thought, and we'd have to be careful not to drastically slow down the cost
> of instantiating new concrete types from a heavily-extended generic class.
>
> Jordan
>
>
> On Aug 24, 2016, at 7:23, Zhao Xin via swift-users <swift-users at swift.org>
> wrote:
>
> I was trying to implement a final class to conform NSCopying by extension.
> List<T> was a class in Realm object database.
>
> final class List<T>
>
> My implementation:
>
> extension List:NSCopying {
>     public func copy(with zone: NSZone? = nil) -> Any {
>         ...
>     }
> }
>
> I got an error called "@objc is not supported within extensions of generic
> classes.". Any idea why there is a limitation of this? Thanks.
>
> Zhaoxin
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160825/093740d2/attachment.html>


More information about the swift-users mailing list