Search code examples
swift3nslayoutconstraint

Nil is not compatible with expected argument type 'NSLayoutAnchor<NSLayoutDimension>' Swift 3


I recently converted my code to Swift 3. When setting a constraint I no longer can pass in nil to set a constant value. I've searched similar posts and the documentation and can't seem to find what to do in this case.

enter image description here enter image description here


Solution

  • In the documentation for NSLayoutConstraint the type of the first argument is not optional. So, you cannot pass nil. What you're trying to achieve can be done using the constraintEqualToConstant method.