Eric
Eric

Reputation: 3841

Getting error when adding constraint

I'm trying to set a constraint on 2 views so that they touch each other like this:

enter image description here

I tried setting constraints programmatically:

[self addConstraint:[NSLayoutConstraint constraintsWithVisualFormat:@"[_firstView][_secondView]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_firstView, _secondView)]];

But I get the following warning:

Incompatible pointer types sending 'NSArray *' to parameter of type 'NSLayoutConstraint'

What am I doing wrong?

Upvotes: 4

Views: 755

Answers (1)

nhgrif
nhgrif

Reputation: 62072

The addConstraint: method expect a single constraint, however the constraintsWithVisualFormat: returns an NSArray of zero or more constraints.

Try adding an s.

[self addConstraints:/*your NSLayoutConstraint constraintsWithVisualFormat: call */];

Apple's naming conventions can usually help you out here. Notice that constraintsWithVisualFormat is plural while addConstraint: was singular (and addConstraints: is plural). Use these as your clue in the future.

Upvotes: 2

Related Questions