Copying UIView using NSKeyedArchiver throws NSInvalidUnarchiveOperationException

ios, iphone, nskeyedarchiver, uiview, xcode

Solution

If we are using `Archive/Unarchive` with `UIImageView` , I am facing error, though I fixed that highlight issue.

let NewView = whichView.snapshotView(afterScreenUpdates: true)!

The above line will give you best solution.

Problem

Using this to copy `UIView` ``` UIView copyOfView = [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:originalView]] ``` This throws the following error: `NSInvalidUnarchiveOperationException` `[NSKeyedUnarchiver decodeBoolForKey]: value for key (UIHighlighted) is not a boolean`

Original source