2

How do you use the debugger in XCode to see if a variable is nil?

2 Answers 2

2

If the pointer's address is 0x000000 it's nil.

Hovering over the variable in the debugger should show a tooltip, this will show you the type of the variable, the name and a value. If it is a pointer to an object the value will be the address that it points to. This will be 0x0 if it is nil.

Sign up to request clarification or add additional context in comments.

Comments

2

Just open up the GDB Console and type po myvar or insert a breakpoint after you set your variable and move your cursor over the target variable.

4 Comments

It doesn't say anything. If I type something in gdb it doesn't do anything.
Are you stopped at a breakpoint whilst running the app? It's probably easier to just type p myvar, the output would look like this if myvar is an NSMutableArray and set to nil, $1 = (NSMutableArray *) 0x0.
As Greg mentioned you have to stop at a breakpoint to use both methods
Yeah, I'm at a breakpoint. The other method doesn't work either.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.