我用:
extension UIView {
func copyView<T: UIView>() -> T {
return NSKeyedUnarchiver.unarchiveObject(with: NSKeyedArchiver.archivedData(withRootObject: self)) as! T
}
}
但是我的副本正在丢失可访问性标识符。
copyView.accessibilityIdentifier == nil
如何保存?
答案 0 :(得分:0)
这似乎是一个Apple bug。你应该在Apple Bug Reporter上报告这个。
也就是说,您可以解决以下问题:
extension UIView {
func copyView<T: UIView>() -> T {
let copy = NSKeyedUnarchiver.unarchiveObject(with: NSKeyedArchiver.archivedData(withRootObject: self)) as! T
copy.accessibilityIdentifier = accessibilityIdentifier
return copy
}
}