views:

239

answers:

2

Hi,

I am writing a Core Data-based iPhone app and I am new to Objective-C.

I have a bug that I am really struggling to nail. The iPhone simulator keeps crashing with the following error message:

2010-03-21 17:37:40.583 Patients[3689:207] * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSCFArray insertObject:atIndex:]: index (1) beyond bounds (1)' 2010-03-21 17:37:40.585 Patients[3689:207] Stack: ( 31007835, 2516698377, 31091771, 31091610, 601273, 197333, 3194546, 3141378, 25020, 29768673, 214570, 30740485, 204512, 29114749, 29505379, 29001194, 29252410, 29190487, 30794322, 30791263, 30788680, 39097877, 39098074, 2883503, 9912, 9766 )

This error happens when I press return on a textField. What happens when the return key is pressed is that an attribute on an entity is updated.

I don't know what array is out of bounds as I am not using any arrays in my code!

Is there any way of getting more detail as to where in my code the error is??

Thanks,

A: 

When this happens, try running Debugger from Run menu immediately when the crash happens. It will show you exactly which line crashed. You could then post some code here. Without the code, we can't tell you anything.

Jaanus
I've uploaded a screenshot of the debugger immediately at the crash point but it doesn't make much sense to me.http://www.madebyfiga.com/images/misc/debugger1.png
Garry
+1  A: 

In the debugger menu you can have it break on exceptions. There are a a number of ways to do this.

On way is to select it directly in Xcode from the menu Run->Stop on Objective-C Exceptions.

An alternative way is to add the following entry into the .gdbinit file in your home folder (~/.gdbinit):

fb -[NSException raise]

This will have gdb always break into the debugger when somebody tries to throw an exception. You can also manually add the breakpoint when you launch the application in the debugger. Just leave out the "fb" part of the command when adding.

Hope these help,

Claus

Claus Broch
Figured out the issue - it seems to be a bug in how NSFetchedResultsController handles insertion of new sections. I have changed my approach and dropped the FRC for the time being.
Garry