Constraint must contain a first layout item NSLayoutConstraint

David van Dugteren picture David van Dugteren · Sep 17, 2012 · Viewed 15.1k times · Source

I had my LayoutConstraints working fine, then all of a sudden I started getting this when adding Constraints to my view.

    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]: Constraint must contain a first layout item'
*** First throw call stack:
(0x7cd012 0x2017e7e 0x7ccdeb 0xde6bf1 0x9c487 0x994a3 0x414fb 0x20224 0x5c6c0 0xc30e83 0x78c376 0x78be06 0x773a82 0x772f44 0x772e1b 0x28eb7e3 0x28eb668 0x149465c 0x2cfd 0x2c25)
libc++abi.dylib: terminate called throwing an exception

And there exists no immediate documentation on the internet or on the Apple Docs as to what the error message means.

Just wondering if anyone has encountered this error, and know what I can do to troubleshoot it?

Answer

Pravara Patil picture Pravara Patil · Oct 25, 2012

One more reason for this error/crash can be, the views passed to the [NSLayoutContraint constraintWithItem ...] method are nil.