Marking class as final makes @NSCopying attribute not working at all.
Example of bug in attachments.
//
import UIKit
class MyClass: NSCopying {
var a: Int
init(a: Int) {
self.a = a
}
func copy(with zone: NSZone? = nil) -> Any {
print(#function)
return MyClass(a: self.a)
}
}
class CopyingContainerWithoutFinal {
@NSCopying var value: MyClass?
}
final class CopyingContainerWithFinal {
@NSCopying var value: MyClass?
}
class ContainerWithoutNSCopying {
var value: MyClass?
}
let c1 = MyClass(a: 0)
let container1 = CopyingContainerWithoutFinal()
let container2 = CopyingContainerWithFinal()
let container3 = ContainerWithoutNSCopying()
container1.value = c1
container2.value = c1
container3.value = c1
let value1 = container1.value
let value2 = container2.value
c1.a = 1
print(container1.value!.a) // Must print 0.
print(container2.value!.a) // Must print 0, but actually prints 1. Bug?
print(container3.value!.a) // Must print 1.
Attachment: Download
Environment
xCode 11.4Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, PropertyWrappers | |Assignee | None | |Priority | Medium | md5: 0a3413c9b5880fdad2a5640dfab27de7Issue Description:
Marking class as final makes @NSCopying attribute not working at all.
Example of bug in attachments.