@wadetregaskis wrote a summary of the issue we discovered in this thread, caused by an Objective-C superclass implementing -copyWithZone:
by calling NSCopyObject
.
Wade’s final point is key:
Compounding the problem is that
NSCopying
doesn’t work, by default, on subclasses . You have to overridecopy(with:)
in every subclass […]
We’ve seen this exact pattern before with NSCoding
. But because NSCoding
uses an initializer, we have a tool to enforce its implementation in subclasses: required
. Alas, NSCopying
can’t be modeled with a required initializer, because then you could do something like let base = Base(); let copy = Derived.init(copying: base)
.
Does it make sense to deprecate NSCopying
entirely as part of transitioning Foundation to Swift? Alternatively, if arbitrary protocol methods could be required
, would that be enough to make NSCopying
both useful and safe?