Showing posts with label Errors. Show all posts
Showing posts with label Errors. Show all posts

Monday, January 09, 2012

Making Xcode less difficult

Writing Objective-C code in Xcode can be very difficult.  Especially if you're coming from a different language like Java; not only do you have to learn the new syntax of Objective-C you also have to learn the new development environment and remember what it's like to code in a non-managed environment (i.e. not having the JVM hold your hand when things go awry).

I started working with Xcode and Objective-C about 4 years ago and after many frustrating days (and nights) I found out some great information in an iTunes University video called Advanced IOS Development put out by Madison College.  

It's a very long video, about 3 hours and I'm only about half way through it but I have found some great information in it already that I wanted to share.

Problem: you're running your app on the emulator and it seeming crashes randomly.  You don't get any information about why it crashed the app just quits.

Solution: in Xcode you can set global break points that can stop your app when it crashes, the debugger puts you right on the line that causes the problem!  
Here is how you do it:
  • In Xcode open the Breakpoint Navigator
  • In the bottom left corner of the view is a plus sign click on it to add a new breakpoint.  You will be asked to add an "Exception Breakpoint" or a "Symbolic Breakpoint" choose symbolic.
  • After selecting "Symbolic Breakpoint" a popover window will open fill it in as follows:
    • Symbol: objc_exception_throw
    • Module: libobjc.A.dylib

  • Follow those same steps again to add a new symbolic breakpoint as follows:
    • Symbol: -[NSException raise]
    • Module: CoreFoundation


  • To make the breakpoints global right click (command click - double finger tab - whatever) the break points to move them to the User context


And there you have next time you make a mistake Xcode will stop your app where it breaks - assuming it breaks in your code.  If you tell the frameworks to do something that doesn't work (such as loading a ViewController that won't load for some reason) you're back to the drawing board.

Hope that helps!

-Aaron




Saturday, February 07, 2009

I'm starting to hate this error

So, I'm learning Objective - C now - Yeah so I can be like all of those other iPhone developers.... 

I am doing it for a very specific reason though - over at LifeAware we're trying to port or application to the iPhone platform.  We were recently accepted into Apple's iPhone Developer Network which is kind of cool - it cost $99 of course but cool nonetheless. 

Once we got accepted I immediately ran out and purchased an iPod Touch to do development on.  It is an impressive device - I think it's overpriced - but it is pretty damn cool. 

But - I digress. 

I've been working through a spectacular book on iPhone devleopment called "Beginning iPhone Development - Exploring the iPhone SDK".

It is a fabulous book that has links to an active community forum of a bunch of other people learning together.  If you're looking for a good technical book that is pretty easy to follow and teaches a lot of stuff this is a good one.

However, with all projects you eventually need to step away from the tutorials and start building the next greatest thing and that's when the crazy errors start rolling in.

This is my current nemesis:

2009-02-07 20:53:13.535 NavTest[830:20b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "MySpecialView" nib but the view outlet was not set.'

So I've finally figured it out (thanks to the book) the error is actually pretty decent.  It is saying - a view was requested and it was found but the view couldn't be rendered because the outlet for the view wasn't defined.  Here is a quote from the book that warns about the danger:

When we  changed the underlying class of the file’s owner, the existing outlet connections were broken.   As a result, we need to reestablish the connection from the controller to its view.  Control‑ drag from the File’s Owner icon to the View icon, and select the view outlet to do that.

Which is really the solution to most problems.... RTFM

Cheers,

-Aaron