Exception with insertObject:atIndex: on iOS6

后端 未结 2 546
感动是毒
感动是毒 2020-12-09 01:03

I\'m getting the following Exception on iOS6 (on an App with CoreData):

\"2012-10-15 10:21:28.952 MyApp[68650:c07] * Terminating app due to uncaught exceptio

相关标签:
2条回答
  • 2020-12-09 01:33

    This is probably because either iOS5 did not throw an exception for this error (and should have, but now iOS6 throws one which is better than having erratic behavior later), or because you have some different behavior in iOS6 which makes your object nil whereas it was not in iOS5.

    Whatever the reason, you can add a Symbolic Breakpoint on the insertObject:atIndex: symbol, so that it will break every time this method is called, wherever it is in your application (in your own code or not).

    • Go to the "Breakpoints Navigator" view (Cmd-6 shortcut)
    • Click on the "+" button to add a symbolic breakpoint Add symbolic breakpoint
    • Set the symbolic breakpoint to break when it hits the symbol [NSArray insertObject:atIndex:] Edit Symbolic Breakpoint

    Thus you can see when this is called with a nil value for the first parameter and fix your problem where it occurs.

    You can also instead add an Exception Breakpoint to break when an exception is thrown, thus knowing when in the code your exception occurs. This is another way to let you know which part of the code (your own or another) generate the exception.

    Exception Breakpoint

    Once the breakpoint has been hit and the program stops before the exception occurs, you can check in the call stack what part of your own code led to trigger this exception at the end.

    0 讨论(0)
  • 2020-12-09 01:40

    The reason for the crash is that the object you are trying to insert is nil. This means it is not properly instantiated. This in turn means something has gone awry before you reached that exception.

    Could you post the code that alloced and initialized the object you were trying to insert?

    In order to find the relevant line of code, please try the following: Go to the "Exception" tab in your Xcode project:

    Exception tab

    Then click the "+" button (at the bottom of the page) and select "Add Exception Breakppoint ...". Leave all settings to their defaults and click "Done".

    If you rerun your project it should now stop at the relevant line of code before the exception is thrown. Then you can move up the call-stack and identify from where in your code you called the library function that is responsible for this behavior. Then try to see if all objects are correctly initialized at this point.

    0 讨论(0)
提交回复
热议问题