title: Copy/clone UIView in swift in 2021?
body: <p>There some similar questions but the answers use deprecated methods.</p>
  <p>My solution which is similar to them but with modern methods:</p>
  <pre><code>func copyObject&lt;T: UIView&gt;() throws -&gt; T? {
          let data = try NSKeyedArchiver.archivedData(withRootObject:self, requiringSecureCoding:false)
          return try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? T
      }
  </code></pre>
  <p>The problem is it doesn't work fully (and it seems the other questions-answers have the same problem) - one of subviews has corner radius which is not copied. How to solve this issue?</p>