166

I am very new to this. I followed Apple's tutorial step by step for the iPhone project "HelloWorld". I ran it in the iPhone 5.0 simulator and it crashed:

2012-11-02 14:46:06.782 HelloWorld[9880:c07] * Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named NSLayoutConstraint' * First throw call stack: (0x14a2052 0xea2d0a 0x144aa78 0x144a9e9 0x32f7d7 0x32f9af 0x32f6b7 0x23036d 0xd7e2c 0xd83a9 0xd85cb 0x38a73 0x38ce2 0x38ea8 0x3fd9a 0x10be6 0x118a6 0x20743 0x211f8 0x14aa9 0x138cfa9 0x14761c5 0x13db022 0x13d990a 0x13d8db4 0x13d8ccb 0x112a7 0x12a9b 0x1fed 0x1f15 0x1) terminate called throwing an exception(lldb)

Can someone please tell me what went wrong? I'm using Xcode 4.5.

Jack
  • 13,571
  • 6
  • 76
  • 98
user1703590
  • 1,661
  • 2
  • 11
  • 4

4 Answers4

576

By default, when you create a new iOS project in Xcode 4.5, your storyboard or XIB is set to use Autolayout, which is a new feature in iOS 6.0. The NSLayoutConstraint class is part of the Autolayout system, and it doesn't exist in older versions of iOS.

If you want to deploy your app to an older version of iOS, you need to change your storyboard or XIB to not use Autolayout. It's a checkbox in the File Inspector:

turning off autolayout

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • 29
    I used ScreenFlow for capture and cropping. I used Photoshop to turn the .mov into a .gif. – rob mayoff Jan 09 '13 at 19:09
  • This applies for xib's too! – virata Jan 16 '13 at 07:47
  • Doing this disables view rotation from portrait to landscape even having the methods implemented. How did you solve the issue if you still want the rotation to take place? Thanks in advance, and ... nice gif ^^ – aGit Jan 17 '13 at 00:21
  • @robmayoff thanks for the gif and the perfect answer. my issue got solved in a second. :) – ishhhh Feb 15 '13 at 06:27
  • I liked this so I created my own for exception breakpoints. http://www.rsaunders.co.uk/2013/06/add-exception-breakpoint.html – Robert Jun 25 '13 at 17:17
  • @Robert Check out [How to Snatch the Error Code from the Trap Frame in Xcode](http://qwan.org/2013/06/18/how-to-snatch-the-error-code-from-the-trap-frame-in-xcode/). – rob mayoff Jun 25 '13 at 17:18
  • @robmayoff hey, was wondering if you could point me in the direction of the tool you use to create the animated gifs from screencasts. Thanks – Fogmeister Jan 14 '15 at 13:40
21

Your Xib file (Interface builder file) contains AutoLayout elements, which iOS 5 does not support.

In Xcode, go to your .xib file(s), and for each one, turn off AutoLayout. There should be a checkbox on the left hand side saying "Use AutoLayout", uncheck it and try again. (This is under the first tab in the left hand side inspector, when you have File's owner) selected.

WDUK
  • 18,870
  • 3
  • 64
  • 72
8

I stumbled into this error when I was working on an older project I wanted to update. I had selected the "Use Autolayout" checkbox to start working with constraints, but had forgotten to update my Deployment Target setting to iOS 6.

jbryant
  • 211
  • 2
  • 6
7

You need to run it in iPhone 6.0 simulator. Your error:

* Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named NSLayoutConstraint' *

Suggests that you are using autolayout, which only works on iOS 6.

yeesterbunny
  • 1,847
  • 2
  • 13
  • 17