title: Cannot convert value of type 'NSLayoutAnchor<NSLayoutXAxisAnchor>' to expected argument type 'NSLayoutAnchor<AnyObject>
body: <p>I'm trying to write an extension for UIView to make it easier to set anchors for a view.</p>
  <p>The idea was to write a setAnchors method like this:</p>
  <pre><code>import UIKit
  
  extension UIView {
  
      func setAnchors(top: Anchor? = nil,
                      bottom: Anchor? = nil,
                      leading: Anchor? = nil,
                      trailing: Anchor? = nil) {
          translatesAutoresizingMaskIntoConstraints = false
          if let top = top, let anchorType = top.type as? NSLayoutAnchor&lt;NSLayoutYAxisAnchor&gt;, let constant = top.constant {
              let constraint = topAnchor.constraint(equalTo: anchorType, constant: constant)
              constraint.isActive = true
          }
  
          if let bottom = bottom, let anchorType = bottom.type as? NSLayoutAnchor&lt;NSLayoutYAxisAnchor&gt;, let constant = bottom.constant {
              let constraint = bottomAnchor.constraint(equalTo: anchorType, constant: constant)
              constraint.isActive = true
          }
  
          if let leading = leading, let anchorType = leading.type as? NSLayoutAnchor&lt;NSLayoutXAxisAnchor&gt;, let constant = leading.constant {
              let constraint = leadingAnchor.constraint(equalTo: anchorType, constant: constant)
              constraint.isActive = true
          }
  
          if let trailing = trailing, let anchorType = trailing.type as? NSLayoutAnchor&lt;NSLayoutXAxisAnchor&gt;, let constant = trailing.constant {
              let constraint = trailingAnchor.constraint(equalTo: anchorType, constant: constant)
              constraint.isActive = true
          }
      }
  }
  
  struct Anchor {
      var type: NSLayoutAnchor&lt;AnyObject&gt;
      var constant: CGFloat? = 0.0
  }
  </code></pre>
  <p>which can be called like this:</p>
  <pre><code> topView.setAnchors(top: Anchor(type: view.topAnchor), leading: Anchor(type: view.leadingAnchor), trailing: Anchor(type: view.trailingAnchor))
  </code></pre>
  <p>I am getting this following error:</p>
  <blockquote>
  <p>Cannot convert value of type 'NSLayoutAnchor' to
  expected argument type 'NSLayoutAnchor'</p>
  </blockquote>
  <p><a href="https://i.stack.imgur.com/6oeTq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6oeTq.png" alt="enter image description here" /></a></p>
  <p>I know I could give topAnchor as <code>NSLayoutYAxisAnchor</code> and so on, and give constant also as parameter to this method to make this work, but I was wondering if there is a way to make it work with this Anchor struct?</p>