Tag Archives: Xcode

What is an Exception Breakpoint

Sometimes Xcode just throws an error message that isn’t very helpful. That’s usually when we have to try and figure out why something didn’t go the way we expected it. Other times however, Xcode tells us very clearly which element it isn’t happy with – we fix it and our app progresses. Why can’t it always be that way?

Well that’s because at those unhelpful times, Xcode is technically picking up an “exception”, but it tries to continue to run the programme. That’s when we end up with an error message which isn’t related to the actual problem.

An Exception Breakpoint can help. It’s something we can set and therefore force Xcode to stop when the problem occurs, not several lines later. Here’s how we do it:

  • with the Navigator pane open, select the 6th tab from the left (the Breakpoint Navigator)
  • at the bottom left, click the plus sign to add a breakpoint
  • from the context menu select Add Exception Breakpoint
  • leave all default values and hit Done

Next time Xcode will not try to be heroic and keep going. Instead, expect a more helpful error message.

Screen Shot 2013-03-16 at 23.03.17

Also check out: https://developer.apple.com/library/ios/#recipes/xcode_help-breakpoint_navigator/articles/adding_an_exception_breakpoint.html

Hilarious Xcode Error Message

Xcode_iconI’ve been working on an iOS App recently which deals with several date methods. Usually when something goes wrong Xcode displays very dry messages such as “Array out of bounds” or something rather unhelpful (like the complete stack output with no clue as to what actually went wrong).

I was accidentally passing nil into an NSDateComponents method – and instead of crashing (which is what I would have expected), Xcode displayed this super funny message in the log console:

[__NSCFCalendar components:fromDate:toDate:options:]:

toDate cannot be nil

I mean really, what do you think that operation is supposed to mean with a nil toDate?

An exception has been avoided for now. A few of these errors are going to be reported with this complaint, then further violations will simply silently do whatever random thing results from the nil.

It made me smile 🙂

Continue reading Hilarious Xcode Error Message

How to fix “this class is not key value coding-compliant” after accidentally adding an IBOutlet instead of an IBAction

It has happened to us all: you’re in a storyboard, you’re using the Assistant Editor, you want to control-drag from a button into your code and create an action.

But sadly you forget to select “Action” from the drop down menu and instead create an outlet.

No biggie you think, deleting the outlet code. You go back and create the action properly, run the app… and get an error message such as this one:


*** Terminating app due to uncaught exception ‘NSUnknownKeyException’, reason: ‘[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key badAction.’

Yikes! Unless you’re using Version Control, there is no way to undo adding that bad outlet. So you ask yourself: Will I have to start from scratch, or is there a way to fix your app?

Yes this is fixable – all we need to do is examine our storyboard file in Source Code mode, then find the problem and eliminate it. Here’s how you do it:

  • With the left pane open (Navigation Inspector, showing all your files), select your storyboard and right click/control click to bring up the context menu. Select View as Source Code

badAction1

This will allow you to see what the storyboard actually looks like in XML. Hit Option+F to bring up the Find in Context menu. Now search for whatever is causing you a headache, then delete the entire line. Make sure the opening and closing brackets are selected too.

In my case, all this needs to go:

badAction2
You may see more than one occurrence of your action in this file – we only want to get rid of the “outlet”reference here. If you delete all occurrences it’s not a big problem, but you will have to re-connect your actions to the code later.

Once you’re done, run the app again and all should be fine.

To display the storyboard in the visual editor again, just control-click the file file again, and select “Open as – Interface Builder, iOS Storyboard”.

When Xcode 4.5 suddenly stops running your app on a device (could not launch app)

I’ve had this problem that Xcode 4.5 would run my app fine in the simulator, but didn’t do so anymore on the device. Something about the “derived data folder was not found”. I checked, it was definitely there.

Then I found this post on Stackoverflow to show some suggestions: http://stackoverflow.com/questions/11456312/xcode-suddenly-stopped-running-project-on-hardware-could-not-launch-xxx-app

This solution worked for me – Thanks Dhilip: http://dhilipsiva.blogspot.in/2012/07/xcode-could-not-launch-app-no-such-file.html

How to use Xcode with a remote Git server

Xcode_iconImagine you’ve created a project in Xcode with a local Git repository. Now you’d like to put this online so that others can collaborate with you. How do you do that?

This has been puzzling me for a while, and there doesn’t seem to be a clear documentation on this subject – so I’ve decided to take some notes as I figured it out. Here are step by step instructions on how to make it work.

All we need is a server running Git and SSH credentials to that server to get started.

Continue reading How to use Xcode with a remote Git server