1

In Xcode 6.3, how do I view the values of objects such as:

arrary count: myarray.count

TableView index: indexPath.item

These don't show up in the debugger and I don't know how to print them out into the console.

2 Answers 2

2

When the app is paused on a breakpoint, the debugger (lldb) has a few commands available.

To (p)rint (o)ut an object, you can do:

po myObject.debugDescription
po myArray.count
...
Sign up to request clarification or add additional context in comments.

Comments

0

The easiest way is to log them to console using NSLog / println depending on which language you use.

In Objective-C:

NSLog(@"My Array Count: %i", myarray.count");

In Swift:

println("My Array Count: \(myarray.count)")

Same goes for indexPath.item - you can print item, row, selection or even whole content of your cell, such as textLabel's text, the same way you print number of items in an array.


For more advanced way of accesing number of items in your memory (such as a count of an array), you can always use Apple's Instruments application, and its build in Allocations.
From there you can track how many objects you have in your memory:

enter image description here

2 Comments

I don't want to litter the code with these statements. I'd like access from the debugger via breakpoints...just like all other variables.
po is what I was looking for. I think that is the only way to access the two variables above?

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.