I was using the below func to Make Copy of a UIView :
extension UIView {
func copyObject<T:NSObject>() throws -> T? {
let data = try NSKeyedArchiver.archivedData(withRootObject:self, requiringSecureCoding:false)
return try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? T
}
}
Recently I have updated my app to support iOS 16. I am getting the below warning for the above code:
'unarchiveObject(with:)' was deprecated in iOS 12.0: Use +unarchivedObjectOfClass:fromData:error: instead
'archivedData(withRootObject:)' was deprecated in iOS 12.0: Use +archivedDataWithRootObject:requiringSecureCoding:error: instead
After fixing the warning The code looks like this:
func copyView<T: UIView>() -> T {
let data = try? NSKeyedArchiver.archivedData(withRootObject:self, requiringSecureCoding:false)
return try! NSKeyedUnarchiver.unarchivedObject(ofClass: UIView.self, from:data!) as! T
//return NSKeyedUnarchiver.unarchiveObject(with: NSKeyedArchiver.archivedData(withRootObject: self)) as! T
}
Now when I try to copy, I am getting below error
error: Error Domain=NSCocoaErrorDomain Code=4864 "This decoder will only decode classes that adopt NSSecureCoding. Class 'UIView' does not adopt it." UserInfo={NSDebugDescription=This decoder will only decode classes that adopt NSSecureCoding. Class 'UIView' does not adopt it.}