kodeco.com Forums

Intermediate Debugging with Xcode 8

Learn some intermediate debugging techniques with Xcode 8, such as breakpoint logging, conditional breakpoints, basic LLDB usage, and more.

This is a companion discussion topic for the original entry at https://www.raywenderlich.com/721-intermediate-debugging-with-xcode-8

Thanks mate. I did not realise how powerful the Debugger was.

1 Like

Can you add some more detail to “Variables View & Return Values”? I’m not able to replicate what you’ve got on the screen. I’m close, but not quite there (do X, do Y, do Z & your screen will look like this). I’m missing a step and I know it’s important…but I don’t know what.

Hello dcdude, thanks for the great question!

Let me walk through the steps.

First, be sure the breakpoint is still fixed in the empty validation method.

Then, with the app restarted, add a new friend, and press the OK button (this could very well be the missing step). The application should stop at the breakpoint, and show the debugger with the Variables & Console View displayed since we set that up previously (Setting up the Debugger Console).

Once the Debug area appears in Xcode, you can choose the Step Out button which is located directly above the Variables View. Stepping out of a method will update the Variables View to display the Return Value for that method.

Let me know if you are still unable to replicate what is on screen. Also, I will update the tutorial soon to clarify these steps.

Hope this helps! :]

1 Like

I’m unable to reproduce it with the return value.

I add the breakpoint to the line:
if name.hasText, isValidDateComposedOf(month: selectedMonth, day: selectedDay, year: selectedYear) {

Then upon pressing step out I get to a page with a bunch of hex values

Am I missing something?

Hello simonqq,

You’re just about there. Add the breakpoint inside the empty validation method like so:

Then, after running the application and reaching this breakpoint, you should be able to step out and see the Return Value correctly.

Let me know if that doesn’t work.

That’s odd, I don’t reach that endpoint at all.

When I only add the break point to the empty validation method it doesn’t do anything.

When I add the breakpoint to the if name.hasText, ... line and the empty validation method and then step in to it, i get to the name but never the isValidDateComposed(_:_:_:) method

Hello simonqq,

If you see a page with hex values you might have another issue. If you want to provide a Dropbox or Google Drive link to the project, I can take a look and see what the issue is. Thanks!

Thanks @georgeandrews! This is the dropbox link

Hello @simonqq, I just tried your project and everything worked okay.

Just to double check, are these the steps you are taking?

  1. Add breakpoint to empty isValidDateComposed method.
  2. Run application.
  3. Choose Add a friend cell.
  4. Enter in a name.
  5. Choose OK button.
  6. Application should stop at breakpoint in isValidDateComposed method.
  7. Choose Step Out.
  8. Review Variables View, it should show Return Value at top.

Ah silly me. I left the name field blank which is why it would never get to the isValidDateComposed because the name.hasText was false already

It works now (: Thanks @georgeandrews!!

@simonqq: Awesome! Good to hear :]

If you are using R.swift it creates a directory with name R.swift. The script search in all types of files and throw an error if there’s a directory with name *.swift. To resolve this, restrict the find command to only search in files. The final script:

echo "searching ${SRCROOT} for ${TAGS}"
find "${SRCROOT}" \( -type f -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"
1 Like

@alessandro_ufms Thanks for the tip!

Hi George,

I’m with you up to the “Conditions for successful debugging” part and then I can’t continue. In the application (simulated) I select a “friend”, click the “add” button but I can’t put anything in the gift field. It is greyed out and if I click it, the program just unwinds to the previous screen. How can I enter “shoes” as you describe.

Hello @graham_stokes,

“Gift Name” is a placeholder so it should be okay that you see it greyed out. But I can see what you mean with the unwind behavior.

The unwind behavior appears to happen randomly when I click outside the text fields. I wonder if the issue is related to the Stack View. It is like it causes the cancel button to dismiss the View Controller when it is not actually being clicked.

Let me try to help you further. Which device are you simulating? With an iPhone 7 I am able to access text fields and buttons okay.

I hope there will be a video series dedicated to this one day! I would love to learn more

1 Like

I am simulating an iPhone SE just because that is the real device I have. I tried an iPhone7 simulation and I get exactly the same result.

@graham_stokes: Hmm, I’m not able to reproduce the issue without clicking to the left or above the “Gift Name” text field. I imagine you’ve already tried clicking into righthand side of the text fields too. I’ll keep looking into the issue to see if I can determine why it is causing the View Controller to dismiss on you.

Well please look no further. That seems to be the problem. It appears that unless the user clicks in just the right-hand half of the text box you get a “cancel” behaviour instead. My apologies for taking up your time with this, but a near lifetime of habit is not easily overcome. Anyway, if you click anywhere past the halfway mark it works. Is there any particular reason for this behaviour ? Personally I find it rather counterintuitive for a text field because - in English at least - we always write left to right so the natural place to click would be on (or to the left of) the “Gift Name” prompt.