I am trying to make List< T > conform NSCopying. I can't because:
- @objc is not supported within extensions of generic classes.
- I can't inherit List as it is a final class.
- If I implement "public func copy(with zone: NSZone? = nil) -> Any" without marking conform NSCopying. I just get error:"...copyWithZone:]: unrecognized selector sent to instance"
So although there is copy() in List< T >, we can never really use it.
Current I have to make copy outside of List< T >, using iteration. I can't simply using instanceOfList.copy().
It's not necessary to make
List<T>conform toNSCopyingin order to extend it with a copy member function unless you're trying to copy it within a generic context from Objective-C.NSCopyingis a legacy protocol that does not make a lot of sense to use in pure Swift. It is class-bound and does not have a very nice type signature.If you're trying to use
NSCopyingin a generic context in pure Swift, consider defining your ownCopyableprotocol and extending types to conform to that. Since it isn't@objc, you should be fine. Existing types that already conform toNSCopyingwill require extensions to also conform toCopyable, but you can put the logic in an extension ofNSCopying.Now, I'm a little curious why you might be trying to conform
List<T>toNSCopying. Are you looking for an unmanaged copy of the list? You could just useArray(myList)to get anArrayfrom aList.