Friday, November 9, 2012

Solution : Could not Instantiate class named NSLayoutConstraint


Finally I got a project which I can build now with Xcode 4.5 and their was a very interesting bug that I came across.

The Bug Scenario: I made an app and as per the client request I wanted to make the application compatible with the previous versions of the iphone i.e. from iphone 4.3 to iphone 6.1.

So I made a very simple login view and ran it by selecting the iOS 6 simlator and was very much happy to see the login view running fine. Now what I did is selected the iPhone simulator 4.3 version and then ran the application keeping my fingers crossed that it will run fine and will have no issues.

But ALAS!!! I was wrong when I ran my application in iOS 4.3 the application crashed with a love letter in the console which said “ Could not Instantiate class named NSLayoutConstraint” well at first glance I did’nt know what that meant but after going through some developer forms I figured it out that it had to do with some settings of the XIB file.

So lets have a look at  those settings that I am talking about with these settings in place you can easily run your application with Xcode 4.5 from any deployment version you select in the xcode upto the latest version of the iOS without the NSLayoutConstraint crash.

To resolve this crash all i had to do is deselect an option from the Xcode 4.5

- Select the XIB file from your bundle, this will open the xib file.

- From the Utilities section (the one to your right)




- Select the file inspector sub section.






- In the interface-builder document their is a check mark for Use AutoLayout  in the Interface builder Document section which is by default selected when you create your views in XIB using Xcode 4.5.




- If you want to give your application support from any previous version of iOS to the latest version then kindly un-check this option from the interface builder settings.





Now when you run your application it should run fine with all the versions of iOS .

Hope this helps you in saving some time in development.

Happy iCoding and Have a nice day.

4 comments: