And I'll get us back to a known state.
Well, there we go.
Now, the next command that I want to show you is print object.
And print object displays a description of an object that you specified.
And the output that you'll get is similar to what would happen if you used
the expression command and then use print LN, like we just saw.
Now, the abbreviation for print object can all be done with PO,
instead of just P, space, O, it's all PO.
And we'll run this for the bugs array.
And we can see that it is empty again.
Now let's try running PO for self.
And this time, LLDB does its best to give us description, just like we saw
earlier when we were implementing printable and debug printable.
But because those things are not implemented, this is the best it can
do so it gives us the type, breakpoint bug view controller, and the address.
Now if we were to implement printable and debug printable,
like we saw earlier, then when we use the PO command,
LLDB will choose the most specific protocol and show that description.
So, Debug printable is considered more specific than printable.
So if Debug printable was implemented, it would show it.
If printable is the only thing implemented,
then PO would just display the printable description.
So, we'll show that as an example real quick.
I'll stop, and we'll go to the bottom of this file.
And let's implement these protocols in an extension.
And now that we've implemented both the Printable and
DebugPrintable protocols, let's try printing out self again.
And we see that because debugDescription is the more specific, or
DebugPrintable is the more specific protocol, that's what's used.
So, hello from DebugPrintable.
And I'll stop, and let's comment this out, and only implement Printable.
Let's bring back up the same situation.
Now, if we PO self, we get hello from Printable.
So, that was pretty cool, but now I really want to show off the flexibility
of the command line interface.
This next example's going to be a little advanced, so don't worry if
you don't follow everything the first time I show it to you.
We're going to use it again in an example later in the lesson.
So, to start, what I've done is kind of set us up again.
We're in the add bug to view, and we have a breakpoint set that we've
reached, and I've already allowed it to run so that all these bugs were created,
and then I've triggered it again by tapping when the breakpoint was active.
And the reason that I did that was I wanted to be able to print out
the bug object.
And you can see all these image views here, and
we're going to use one of these raw addresses.
So, I'm going to copy this for later use, and let's go ahead and
clear this out.
Make sure it's copied.
Okay, there we go.
So, we're going to start with the expression command, but this time,
we're going to use Swift's unsafe Bitcast function.
And the unsafe Bitcast function, it's going to allow us to convert
the raw address into an object that we can actually interact with.
And this might be really useful in cases where you have the memory address for
an object, but you're unable to access its properties and values.
So, let's see.
Can I actually look at bugs?
There's one of them.
And yeah, we can interact with some of it.
But let's imagine that we couldn't.
And there are cases where this will be handy.
So, here's how it can be used.
The first argument is going to be our raw address.
And this is the raw address that we saw earlier for one of our bugs,
in the bugs array.
And we know that this address refers to a UIImageView,
because that's what is contained in the bugs array.
And so, for the first argument we have the raw address, and
then in the second argument we have the UIImageView.self),
which is going to allow us to cast the address into a UI image view object.
And we'll hit enter.
So boom, there we go.
LLDB has just converted our raw address into a UI image view object and
it's even stored it into a temporary variable called $R4.
Now, if we wanted to instead use our own variable name instead of the $R4,
or whatever it ends up assigning it,
we can instead run the same expression, and we'll use let $bug1.
You need to do use the $, that's special for the console debugger here.
Hit Enter, and now, if we run the expression
println with our variable, there we go.
So, notice here the print output is the exact same output that we would get
if we print out bugs, or we scroll up to the top, lot of bugs here.
Here we go, so, for the first one, I think it stops right there.
There's our first UIImageView, and this matches exactly the UI image
view here that's now contained in the variable above one.
And I can even change bug one's values.
So we'll run another expression, so
we'll say $bug1.frame = CGRect.
And let's print this guy back out.
And there we can see that the frame has now been updated to have X and
Y of 0, and a width and height of 64.
And because we know that bug one refers to the same thing as the first bug in
the array, if we are to print out the bug's array,
we should see the same thing.
And there we go.
So the frame for the first bug, (0 0; 64 64).
Now, again, don't worry if this example is kind of hard to follow at first.
We're going to demonstrate using this again later in the lesson.