Description This application contains information about Solar System and planets. People also like. Netflix Free. QR Scanner Plus Free.
Office Free. Web VPN Free. Flash Browser Free. C Lite Browser Free. Microsoft Authenticator Free. Additional information Published by MaciejGrabek. And Swift is a strict language and doesn't allow you to call functions that haven't been strictly defined.
However, Objective-C code can run wild and free in Objective-C world and you can pretty much do whatever you like. I mean it's a dynamic language so you can call functions like this.
So what we need to do is to tell the debugger to evaluate this expression in an Objective-C syntax. And the way to do that is to use expression with the option - l objc.
That tells expression that you're about to give it Objective-C code even though you're in a Swift frame. And we'll give it -O, tell it that we also want the debug description the same as po would do and -- to indicate that there are no more options. The rest of the line is just raw expression input. So we should be able to then give it the Objective-C format of this method call.
Unfortunately, that doesn't quite work and the reason for that is that expression will create a temporary expression context for the Objective-C compilation, and it doesn't inherit all the variables from the Swift frame. So there's a way around that, though. If we just put view in back ticks. Back ticks is like a step that says first, evaluate the contents of this in the current frame and insert the result, and then we can evaluate the rest.
And now we get the recursive description. So using this, we can see all the debug descriptions for all the views. And I'm interested in the scoreboard views, which host these labels, so we can find the memory address for one of those. And now we can use po memory address, which you might be familiar with if you're an Objective-C developer. Well, that doesn't work and that's because Swift doesn't treat numbers as pointers and de-reference them for you.
So once again, we need to do this from an Objective-C context. So we could do the same thing we did before, but I find this to be so convenient that I like to shortcut this down to just a simple short command. So I'm going to do that by using command alias, and I'm going to call that command poc. So now that I've created an alias, I can simply poc that memory address and see the debug description for that object.
I'd like to show you another way to look at the description of an object if you only have its memory address. And in Swift, you can use a function called unsafe bit cast. Give it the memory address and then it's unsafe because it's up to you to provide the correct type, so I'll give it scoreboard view.
And now we see we can use unsafe bit cast to see the debug description for an object. Now the great thing about unsafe bit cast is that it returns a typed result, so we can call our functions and property names on it such as. And in this case, I'd like to inspect a center point and then modify that center point.
Let's change it to we can see it has changed to , but the view in the simulator hasn't moved. Well, why not? Well, we're paused in the debugger, so cronomation isn't currently applying any view module changes to the screen's frame buffer. But we can ask cronomation to do that for us, just use the expression ca transaction. So now, I can just use these two lines to fix the new positions and continue flashing and we can move around.
And in fact, I find this to be so convenient that I kind of wanted to wrap all this up in just a single command to nudge views around, and so that's what I did. Let me show you that. I'm going to switch to terminal and open a Python file. Why a Python file? So I've created an LLDB Python script to create a nudge command, which takes an x offset, a y offset and a view expression, and you can use that to nudge views around while paused in the debugger.
Now, it might look like a sort of long script but most of that is argument pausing. The core of it, in the middle, is just calling out to the expressions we would call in manually.
We don't have time unfortunately to go into detail in this script. But we're going to make this available for you guys to download, so you can see how it works and use it as the basis for your custom debugging commands. Let me show you how to enable a script like this. Just edit your. I'd also like to add some of the aliases that I find convenient, such as the poc alias I created before, and an alias for flushing the transaction.
I think I'll remember this one. I'm going to copy command script import so we can just paste it in to the debug session to save us restarting that session. And now we have a command called nudge. So I can, let's say, nudge zero horizontally, minus five vertically, give it the memory address of that view and start just nudging it around in the simulator.
The great thing about LLDB is if you just hit enter on a blank line, it repeats the previous line, so it's great for nudging. And I can nudge it across to the right a bit, just to get it right. And then let's do the other view. We can give it any view expression, say the attempts view down to here.
The other feature of nudge is once you've given it a view expression, you don't have to repeat that expression. It remembers that and applies it to the same view that you've specified previously. So something like that looks fine. It's a better layout than we had before.
And what I can do now is take the information provided by nudge, such as the total offset applied to that view relative to its original center point, and then your frame value. Back to my code and modify my layout code or my auto-layout constraints, and I've easily mocked up a new layout for my scene.
Now the last thing to do -- well, firstly, don't forget to check off debug, very important. And then the last thing to do before restarting or recompiling and rerunning is to disable or remove any breakpoints that are injecting expressions because you don't want those lines to be executed twice.
Simply selecting them or a group of them and hitting delete is a quick way to delete those. And so those are some of the debugging techniques that I like to use to enhance my debugging workflows. Notice how we were able to diagnose and fix all four bugs without having to recompile or rerun.
This can be a huge timesaver, especially for complex projects and can be crucial when trying to solve hard to reproduce bugs. So thanks for I hope you enjoyed that and can use these techniques in your debugging sessions. I'd just like to quickly recap all of the features and tricks that we went over during that debug session. So firstly, we looked at how we can use Xcode behaviors to dedicate attempt to debugging and how to use LLDB expressions to modify program state.
We can use auto-continuing breakpoints with debugger commands to inject code live, and we can create dependent breakpoint configurations using breakpoint set one shot as a debugger command action for another breakpoint.
Even when in assembly frames, we can easily inspect the function arguments using po dollar arg one, dollar arg two, et cetera, and we can skip lines of code by dragging the instruction pointer or using the command thread jump. We can request that the debugger pause when a variable is modified using watchpoints, and we can even evaluate Objective-C code in Swift frames using expression -l objc. We can request that view changes are flashed directly to the screen, even while paused in the debugger, using the expression ca transition flush.
And you can add custom LLDB commands, either aliasing commonly used commands to correct shortcuts or by completely customizing and creating your own command using LLDB's Python scripting.
And don't forget to check out our session website. We'll be posting that nudge script soon, so you can download it, check it out, and use it as the basis for your commands. There's one more thing I wanted to cover with you guys and that's just the current LLDB print commands.
So you might be familiar with po. We used it a lot during the demo, and we saw that po requests the debug description of an object, and you can customize that. And that's because po is simply an alias for expression -- object description or expression -O, compared with the p commands, which is simply an alias for expression. And it uses LLDB's built-in formatters to show a representation of that object. The third command that's important to know is frame variable. It differs from the previous two in that it doesn't have to compile and evaluate an expression at all.
It simply reads the value of the name variable directly from memory and then uses LLDB's built-in formatters. So the choice of which command to use is more personal preference and the type of information you want to see while debugging. But it's important to remember that if you ever end up in a situation where expressions are failing or so po and p may not be working for you, if you need to inspect a variable in the current frame, then frame variable should still work for you.
And with that, I'd like to hand over to Sebastian, who's going to tell you about some advanced view debugging techniques. Thank you. Thank you, Chris. I'm excited to show you tips and tricks how to get the most out of Xcode's view debugger. And we'll also take a look at the enhancements we made for Xcode 10 to provide a great debugging experience when you adopt a dark look in macOS. And we'll take a look at this in a demo. So let me switch to the demo machine, and I'll be using the same project that Chris has been using and you already saw that there are two more bugs we have to solve.
So we can see the Mac version of our Solar System app here, we can see that looks pretty good in dark mode but there are two bugs that we have to solve today. First of all, the planet image is not centered horizontally correctly and that is a very obvious bug.
You can see on the right-hand side this Earth image is shifted to the right-hand side, so we'll take a look at this problem. And the second bug is that the description in a popover is not readable in dark mode. Let me show you what that is referring to. When I switch to this app, I can bring up the orbital details information in this popover here. You can see that the labels at the top and nice and readable; however, the label at the bottom is so hard to read, I really have to select the text to read it.
So these are the two bugs we have to take a look at. Let me hide the to do list and let's jump right in. So what I want to do is I want to capture the view hierarchy of this application with Xcode, then inspect it.
We'll find the problem and then hopefully find the fix, so we can all have a beer. The problem is when I switch to Xcode to capture the view hierarchy, this popover will be dismissed since the application goes into the background, and we won't be able to capture its view hierarchy. So what we have to do is we have to capture the app in its active state, and I will show you two ways how to do that. And you can see when I now switch to Xcode how this popover is being dismissed.
First of all, we can use the touch bar, and I'll show you what that looks like by bringing up the touch bar simulator from Xcode's window menu. I'll switch back to the Solar System app and bring up the popover again.
And taking a look at the touch bar, you can see that there's this spray can icon, and when I tap that on the touch bar, you can see that there's a subset of the debug option that Xcode provides in its debug bar. So it's a very convenient way to access these from your touch bar.
And as you can see, I can bring those up with Xcode being in the background, so you can access them even when you're, for example, developing your app in full screen mode. And one of these options allows me to capture the view hierarchy. Now I'm not going to do that because I know that not everybody has a touch bar so I will show you an alternative. I'm going to close the simulator, and I will make use of command click to perform the click on the button in Xcode's debug bar.
Command click is a system-wide gesture that allows you to perform mouse events without activating the application that the mouse event is performed on. So this allowed us to invoke the capture of the view hierarchy. The debugger paused the application while it was still in its active state, and we can see that the UI still renders as if the app was front most and the popover hasn't been dismissed. If you're wondering why that spinning is coming up, that's because the application is paused in the debugger and doesn't respond to mouse events anymore.
Now, you may be wondering, if we take a look at the view debugger here, why the popover isn't visible. Don't worry, the view hierarchy has been captured. I'll get to how we take a look at the popover once we get to that bug, but first I want to take a look at the layout issue of this image view here. So I'll select the image view here and I'll zoom in a little bit.
When we take a look at the inspect on the right-hand side, we can see that this is an underscore NS image view simple image view. Now the fact that this is prefix with an underscore usually hints at the fact that this is an internal class from a system framework and not what we use when we set up image views in code or in interface builder.
So let's take a look at this object in the view hierarchy. And I can do that by using the navigate menu, select reveal in debug navigator. We can now, on the left-hand side, see it relative to its super and sub views. Now, we can see that super view is in fact an NS image view, so that's what we're looking for. We can also see that its super view is a planet globe view, and the super view of the planet globe view is an NS effect view.
So I will select the image view here and we can now also see other properties of the image view on the right-hand side. One example of this is header files. So, if you're one of the people affected, you'll be happy to hear that Xcode now correctly gathers and presents code coverage for both implementation and header files. Now let's talk about code coverage features. The first one is target selection. This is a new option to control not only whether code coverage is enabled or disabled but when it's enabled, you actually control which targets are included.
This can be important if your project builds third-party dependencies that you're not expected to cover by your tests or if you work at a company where another team supplies you with a framework that they already tested. You can customize the included targets in this scheme's test action under options. This means that it can continue to include all targets in code coverage or only hand pick some of them.
Now in the name of more powerful workflows, we created a new command-line tool called xccov. It can be integrated into automation scripts easily, as it produces both human readable and machine parseable outputs.
And at the high level, it gives you detailed view of your coverage data. So, I've mentioned the code coverage data a couple of times, let's look at how it looks under the hood. When tests are run with code coverage enabled, Xcode generates two files. First is the coverage report, or the xccovreport file extension, and that contains the line -- line coverage percentages for each target, source file, and function.
The second one is the coverage archive and that contains the raw execution counts for each of the files in the report. And these coverage files live in your project's derived data directory and additionally, if you pass the result bundle path flag to Xcode build, these files will be placed into the result bundle as well.
Let's look at an example. Here, we use xccov to view the coverage data of our Hello World app. We can see the overall coverage for each target but also detailed coverage for each file and even for each method. And of course, by passing the right flag identification, you can get the same exact information in JSON. This can make it much easier to integrate with other tools. So, as you can see, xccov is very flexible, so I would encourage you to explore its documentation.
Now we talked about use -- viewing code coverage on the command line but the most convenient way is still going to be to see it right next to your source code. You control whether code coverage is shown by selecting editor, show, or hide code coverage. When you do enable it, you'll see the refreshed look of code coverage in the source editor. The whole line highlights when you hover over the execution count on the right-hand side.
And this is just the best way to keep an eye on which of your code is already covered by tests and which still needs more work. Now let me show you all of these improvements in action. So, here I have a project called Dev Cast. It's a simple messaging app and I created the iOS version for this talk last year.
So, this year, I wanted to create a Mac version. But I wanted to share the business logic between the iOS and Mac versions, so I put it all into a framework called DevCastkit and today, my goal is to explore and maybe improve the code coverage of this framework. So, right now, I'm not collecting code coverage, so I just need to turn it on. I'll do that by selecting the scheme, selecting edit scheme, go into the test action, go into options.
And down here, I will just enable code coverage. Now I will run my test by going to product test. Right now, my framework, my test bundle and my Mac app are getting built, and my tests are being run. Now the test finished so let's look at the results. We'll go to the report navigator and to the latest coverage reports.
Here, I can see that I have the -- both targets, the Mac app and also the framework. Now the Mac app only serves as a container for running tests, so I'm not really concerned about its low code coverage. In fact, I would actually not want to see it in this report at all. So, I can do that by editing the scheme again. And in the test action, here -- instead of gathering coverage for all targets, I'll change to just some targets.
This gives me a hard cover list and I will add just the target that I'm interested in, which is the framework. Now I will rerun my tests and look at the updated coverage reports. So, now you can see that I only have the framework in the coverage report. This is what I wanted. So, now I can just focus on this one target. So, I'll jump to the file by clicking on the arrow here. And here, I'll look at my local server class. On the right-hand side, I can see the execution counts for each region of the code so I can see that all of the executable parts of my class are covered by tests.
This is good. Unfortunately, my convenience function, get recent messages, hasn't been called for my tests at all, so I don't know if it's working properly. To fix that, I'll go to the corresponding test file and I will add a new test. This test just puts a couple of messages into a local server and then I call, get recent messages, on it to verify that it returns what I'm expecting.
So, with the new test added, I will rerun my tests one more time. So, great, the test finished. This is exactly what I wanted. So, we saw how I used the target selection feature to only focus on some of the targets. Then I used the coverage report to know exactly which file to focus on. And finally, I used the code coverage integration in the source editor to know exactly which part of my code still needs covering.
Solar System Scope has taught me so many things about space in just one day! I love how realistic it is. Literally the stars, planets, and other things look so real! You guys did a good job, and I appreciate it. One thing I wish the app could do is: Visit Messieurs. I wish it could be able to go to the Messieurs so you can see them up close, and clearly. It would be so beautiful and cool to be able to see the Messieurs up close Visit.
If you could try updating it so you could be able to see other things like Messieurs, Comets, and Satellites, that would be great. Another last thing I wish the app could do is: Exploring other Galaxies! That would be so great, I would never delete the app in my life! If this app could visit other Galaxies, it would be so Awesome, everyone would have it. But other than those two things, the app is incredibly amazing!!! Great job you guys; you have changed my view about space, and the Galaxy.
Thank You.
0コメント