Nef10
Nef10

Reputation: 946

Could not find relevant edges for attributes

I get the following error:

Could not resolve symbolic constant for constraint, because: Could not find relevant edges for attributes: centerX and centerX.

Use a symbolic breakpoint at NSLayoutConstraintFailedToFindDefaultResolvedValueForSymbolicConstant to debug.

If I add a breakpoint at NSLayoutConstraintFailedToFindDefaultResolvedValueForSymbolicConstant it stops at this line:

[self.customNavigationBar.widthAnchor constraintEqualToAnchor:self.view.widthAnchor].active = YES;

This line is called within the viewDidLoad of the view controller. customNavigationBar is a UIView loaded from a nib which already have been added as subview to self.view.

If I try to print out the anchors I am using everything seems ok:

(lldb) po self.customNavigationBar.widthAnchor
<NSLayoutDimension:0x17446cc80 "UIView:0x10115c160.width">

(lldb) po self.view.widthAnchor
<NSLayoutDimension:0x170667080 "UIView:0x1012ae550.width">

Upvotes: 4

Views: 1669

Answers (1)

Jon Vogel
Jon Vogel

Reputation: 5644

This error comes from your choice of constructor for the NSLayoutConstraint.

You probably have something like this:

view.topAnchor.constraint(equalToSystemSpacingBelow: otherView.centerYAnchor, multiplier: 0.25).isActive = true

But you should construct it like this:

let constraint = NSLayoutConstraint(item: view, attribute: .top, relatedBy: .equal, toItem: otherView, attribute: .centerY, multiplier: 0.25, constant: 1)

constraint.isActive = true

Upvotes: 5

Related Questions