Johny D Good
Johny D Good

Reputation: 427

Nil not compatible with expected argument type 'NSLayoutAnchor<NSLayoutDimention>'

this is the problematic code

    // auto layout
    let vertivalConstraint = textField.centerYAnchor.constraint(equalTo: self.codeView.centerYAnchor)
    let leadingConstraint = textField.leadingAnchor.constraint(equalTo: self.codeView.leadingAnchor, constant: 10)
    let trailingConstraint = textField.trailingAnchor.constraint(equalTo: self.codeView.trailingAnchor, constant: -10)
    let heightConstraint = textField.heightAnchor.constraint(equalTo: nil, constant: 37)
    NSLayoutConstraint.activate([leadingConstraint, vertivalConstraint, trailingConstraint, heightConstraint])

let heightConstraint returns the error in the title. How would I go about fixing that.

Thanks

Upvotes: 0

Views: 144

Answers (1)

Robert
Robert

Reputation: 3870

Maybe try:

// auto layout
    let vertivalConstraint = textField.centerYAnchor.constraint(equalTo: self.codeView.centerYAnchor)
    let leadingConstraint = textField.leadingAnchor.constraint(equalTo: self.codeView.leadingAnchor, constant: 10)
    let trailingConstraint = textField.trailingAnchor.constraint(equalTo: self.codeView.trailingAnchor, constant: -10)
    let heightConstraint = textField.heightAnchor.constraint(equalToConstant: 37)
    NSLayoutConstraint.activate([leadingConstraint, vertivalConstraint, trailingConstraint, heightConstraint])

I'm using:

.constraint(equalToConstant: 37)

instead of:

.heightAnchor.constraint(equalTo: nil, constant: 37)

Upvotes: 1

Related Questions