iOS EXC_BAD_ACCESS: How to debug? - ios

I am getting an EXC_BAD_ACCESS. I know what this usually means: Trying to access an object that doesn't exist (anymore) is the most likely cause.
So, where do I find that?
I have read numerous posts on the internet, and they all say:
"Enable NSZombie" in the scheme.
Now when I run the debugger, for what should I look? I can not see any difference...
Note: This is not about a perticular error in my code, but generally how to use the debugger with NSZombie enabled

What I would do it will be to locate a breakpoint just one line above the green arrow showing the EXC_BAD_ACCESS error. Then run again your code and reproduce the steps to generate the crash.
When you get to your breakpoint you can check that your objects are valid objects using right click and print description in the left side of your console within Xcode or typing the command 'po' within the console section in XCode. That's how I usually detect the errors.
Something useful is to trace the stack once the debugger stopped. It show in the left panel the threads and chain of invocations of the methods before the break point.
Hope this helps and hope my description of the alternative in how to track the error helps.

Write code in #synchronized(){} block.
Try this:
#synchronized (self){ //Your Code }

Related

Checking variables in XCODE after app has crashed

My app has crashed telling that he index is out range when I use this team[1] which is surprising because it should have 2 strings in it. I have looked everywhere, in XCODE and the internet, but cannot find a way to see what the team array looks like. Is there anyway to see this? Thanks so much!
click on the left side of your line of code which contains (team[1]) to create a breakpoint.
Then run your app. When it reaches that point it will stop executing so you can check what is going on.
Here is an screenshot on how debugging looks like
You can see your array content in the "variables view"
There is also an example of "po" command on the "console" section
If you just want to use a breakpoint everytime your app crashes just add an exception breakpoint. This should show you where your code crashes and stop just before so you can find out what happened

Does xCode have a debugging console for iOS development like a browser's console?

I would like to easily check property values by typing them into the console (how it works in browser's console). It seems to not be possible. What are the alternatives for easy debugging of different property values instead of breakpoints?
You have to use breakpoints. there is no other options. breakpoints is something like debugger so put break point wherever you need and then when you reach at that breakpoint application will pause and If you simply take mouse curser over that line then also you can know the value of different properties.
you can use po command to print value of any property. write in console(beside lldb),
po then space and than property or variable name and you will get value of it.
You can use step over to go to next line and can use continue execution to continue through all breakpoints.
You can refer this tutorial. It is for old xcode but conceptually same with current.
Hope this will help :)
Type 'po propertyname' into the console and click enter.
In the console you can see the property values using po propertyName.
For view debugging, xcode provides view debugger as this image
No.
Closest thing is the console where you can look at variables and there is an option to look at an exploded view of you UI, where the classes and properties can be inspected. This is activated when you are running your app and click on the button with a hover-text "Debug View Hiererachy". You can find this button just above the console, to the left of the location icon.

Adding a breakpoint to breakpoint navigator for a Core Data error

I'm trying to track down a bug in an app which logs an error in the simulator, but doesn't crash in the simulator or on my testing device. I think I've got a handle on what to do once I can figure out where the problematic code is located, but I'm having a heck of a time figuring out what call is generating it.
CoreData: error: Failed to call designated initializer on NSManagedObject class "OneOfMyManagedObjects"
I'd like to add a breakpoint that stops execution on that error. How would I set the breakpoint navigator to stop execution when that error is logged in the console?
What I've Tried:
So far, I threw some log statements in AppDelegate.swift and the initial ViewController to "see what's going on". Additionally, I've thrown in some manual breakpoints in hopes of tracking down the issue that's generating the console error, but it's taking forever and a day to step through everything. Given the issue lives somewhere between AppDelegate and viewDidLoad of the initial ViewController, I'm baffled why it's taking me so long to spot the problem.
I've added an exception breakpoint for all exceptions in the breakpoint navigator, but this error doesn't appear to be enough to stop execution. I do think it's enough to cause a problem for a minority of users, which is why I'm trying to clean it up.
Special thanks to pbasdf for pointing me in the right direction.
My app uses a TabBarController with 4 tabs. The initial tab is tab 0, so I was looking for a problem between AppDelegate.swift and InitialVC's viewDidLoad. In reality, my problem lived on Tab3ViewController where OneOfMyManagedObjects are displayed.
I had a global variable set on Tab3ViewController that looked like this:
// this was the problem
var oneOfMyManagedObjectsToEdit = OneOfMyManagedObjects()
// I changed it to this and the error went away
var oneOfMyManagedObjectsToEdit: OneOfMyManagedObjects?
Thank you for pointing me in the right direction towards resolution of this problem.

CGContext errors in iOS application

When I run my application it works well, but during transitions between its views I have a lot of CGContext errors in the console output, but the app still works well, no crashes or bugs I didn't see. Description: so I only run my app - all work well - but there appears error messages in the console:
And after any other view transition they appear again and again. So the question - how to fix this? And what may be the reason of this error messages? There a lot of views and code in my application so I don't even know what part is error-prone.But these messages appear after transitions between all views in my app. Thanks in advance.
Look for some method in your code where you call CGContextSaveGState, CGContextSetBlendMode, CGContextSetApha, etc. Chances are that you won´t find many places where you do that.
Well, if you find it, look for some statement (just before those listed in your console log) where a context is created, and try to understand why it fails. You may set a breakpoint on that line and inspect the parameters to the CGContextCreate call.
If you need more help, paste the code you have (hopefully) found.

ActionScript Get crash call stack on iOS

I am using Adobe Air3.4 to develop an app on iOS. However, I met a crash only on release version and this crash doesn't happen on debug version. But I cannot get any crash info such as callstack from iOS. Do you have any method to deal with this kind of problem?
You can wrap the offending code in a try/catch statement. Inside the catch code block, you get an Error object that you can use to get the stack trace:
try
{
// some code that throws an exception
}
catch (e:Error)
{
trace(e.getStackTrace())
}
If you don't know which code is causing the error, and thus where to add the try/catch statement, you might have some luck with the UncaughtErrorEvent -- refer to the examples found at the bottom of the documentation for UncaughtErrorEvent that I linked to.
In fact, if you just want a stack trace in general, create a new Error object and use its getStackTrace() method anywhere in your code.
In addition to checking for errors as above, you should check the crash logs on your device to see if that provides any additional details.

Resources