What's New in Xcode 11

Session 401 WWDC 2019

Start the week with a tour of new features in Xcode 11, designed to help you get from idea to product faster than ever. Discover new ways to edit and organize your source code, new capabilities for designing and previewing user interfaces, and great improvements for debugging and testing. Get an overview for sessions covering developer tools this year.

[ Music ]

[ Applause ]

Good morning.

Well, Xcode 11 has a ton of new features and improvements.

Everything the tools do is in support of getting you from an idea, through development to delivering a great product.

We want the tools to make you more productive, so you can spend more time dreaming up and implementing the next great thing.

So, this year we focused on making it more efficient and faster for you to use the tools we rethought some of the basic workflows.

Let's take a look.

We'll start with a quick recap of Xcode 10.

Now in Xcode 10, there's three main Editor modes, Standard, Assistant and Version, and they live up here in the toolbar, because they apply to the entire windows content.

Now, the Version Editor, it's got three modes of its own, Comparison, Authors, and Log.

So, you've got a lot of functionality available to you.

You just have to pick the one thing that you're most interested in.

Well, we heard your feedback that you wanted more flexibility.

And so, we, we made some improvements.

At first, we took the Source Control Log information, and we moved it over to the Inspector, where it's now available all the time for any file.

So, you can bring it in when you need it, without ever disrupting what's in the main editor area.

And next, we wanted to let you change each Editor Panes mode independently, because we know that different file types like Source Code and Storyboards, they have very different workflows.

So we move the Assistant and the Authors out of the main toolbar down into each editor pane.

So, now you can choose the right mode for each editor.

Now a lot of people use the Assistant today to split up their Xcode window with multiple editors.

Well in Xcode 11, you can create splits anytime, anywhere.

And you can split both horizontally, as well as vertically, all within the same window.

So, there's a lot of added flexibility this year which really does make it easier than ever to work the way that you want.

Now there is no better way to see this than in a demo.

So, here to show it to you now is Brendan.

[ Applause ]

Thanks Ken.

So, we've given Xcode a bit of a renovation this year to give you more control of your workspace.

One of the most visible changes, is to the Editor Splitting and the Assistant.

So, let me start with the Assistant, and its new companion mode, the SwiftUI Canvas.

Each editor has an options menu in the top right.

This is where you control the behavior of the editor.

I have this one set to Editor in Canvas, which means that if there is a SwiftUI preview to show, Xcode will show it.

In this case, there is no preview.

So there's nothing to see.

But if I switch over to a file that has a preview the Canvas appears and Xcode renders a preview of my UI.

Now, the Assistant works the same way.

If I switch over to the Assistant using the options menu, Xcode will show me the generated interface for this file.

But if I switch to a file that doesn't have an Assistant, like the project, it gets out of the way.

There's no space wasted and there's no need for me to spend time manually switching modes as I switch between files.

All right.

When I switch back to a source file, of course, it remembers the state I was in, the Assistant comes back.

So, that's the Assistant, and the SwiftUI Canvas, let's talk about Editor Splitting.

The first thing is, it no longer requires the Assistant.

So, let me get that out of the way.

So, there's a few different ways I can split this window up.

I'm going to start with the Add Editor button, which is up here in the corner, next to the options menu.

When I click that, I get two independent editors.

These editors have their own state.

So if I want to, I can turn on modes like Code Coverage or Authors for each editor individually.

The new editor is active.

So to load another file into it, all I have to do is click on the file.

All right.

So, I've got two editors, I've got two files, let's add a third.

I'm going to split the editor on the left, so I'm going to use the Add Editor button in the left editor.

And I'm going to hold the option key down, so that I can split it in the opposite direction.

The icon rotates to show me what's going to happen.

So, I got an editor on the bottom, and it's active.

So, another click and I've loaded that file.

Sometimes I want to do that the other way around, though, sometimes I want to click on a file and tell Xcode where to put it.

For that, I use the Destination Chooser.

I'll just hold option and shift.

Click on the file that I want, and the Destination Chooser appears.

Now I can just hit return to open it in the active editor.

Or I can use the arrow keys or the mouse to insert a new editor here, to open it in this editor, put an editor there, over here, whatever I want.

I can also use standard keyboard shortcuts to do things like switch tabs, put it somewhere over here, or switch windows, put it somewhere over here.

There's a lot of flexibility here, a lot of power.

So, I'm going to put this one down here under the Globe Scene.

Just press return.

And I've got a set of files that I want to work with, a layout that I like, everything's set, but what if I want to just focus on one of these files for a minute.

That's what the new Focus mode is for, each editor has a button in the corner next to the close button and if I click that, I can zoom in this editor to take over the whole window.

So, let me use that to zoom in and talk about what's new in the Source Editor.

So, one of my favorite new features in the Source Editor is the Minimap that's in the options menu, of course.

So, I'll turn on Minimap, and then let me make it a little bit bigger, so you can see it.

So, the Minimap, of course, is a bird's eye view of your code, it shows you the contours of your code it shows you the syntax coloring.

And it's meant for navigation.

So, it tells you where you're going before you get there, as you hover over different elements, it shows you exactly what it is, so you know where you're going.

It also shows you important landmarks, like, where you have changes in your file or where you have breakpoints, the text you see down here are marks that I've inserted into my code to organize it.

And if I click on one of those, you can see that we render the marks in the Minimap, and the Source Editor the same, including the divider lines to help anchor you as you scroll around.

The Minimap also shows transient information.

So, if I do find, for instance, Minimap shows me all of the matches in my file and it fades some of the other information, so that that stands out, so you can see exactly where you are, and the context of your current match.

All right.

So, that's the Minimap.

Over on the source code side, we've made some improvements, like new syntax coloring options like these declarations you see here.

And we've added new themes, including high contrast themes in light and dark.

And we've given documentation, a big boost in readability.

We've restyled it, so that it reads more like documentation and Xcode now understands a lot more of the structure of your documentation to help make it easier to maintain.

So let me give you an example.

I have here a function which is fully documented.

But, if I add a new parameter to this and I'll make it a double.

I'll give it a value and then let me use my parameter down here, so I don't get any issues.

Now, I can use the action pop over and Add Documentation to fill in the gaps in my code.

Best of all, it also works with multiple cursors, so if you have a bunch of gaps to fill it's really easy.

All right.

So, I got my documentation.

Now, let's say hypothetically, you're on stage in front of a very large audience, and you've just made a typo in your code, and then you've used Code Completion and Add Documentation to spread that typo around.

Well, Edit All In Scope can now clean up your mistakes very quickly, your signature, your code, and now, even the documentation, can be fixed in one go.

[ Applause ]

All right.

One last thing I want to show you in the Source Editor that I'm really excited about is an enhancement to change bars.

So down here at the bottom of my file I have a change that I made earlier.

Change bars have always shown you that a reminder of the changes you made earlier which lines in your file have changed.

If you hover over the change bar, it shows you where on the line those changes are.

But now you can click on the change bar and there's a new Show Change command, which shows an Inline Diff right there in your file.

If you hover over the bar again you can see exactly what it changed from what it changed to, and it's live, so any updates that you make will be reflected immediately in the diff.

So that's everything I want to show in this first editor, let me pop back out to the big picture again to do that I just click the Focus button again.

And my layout comes back just where I left it.

One last thing before I go, I want to do a quick code review of my changes here.

So, I'm going to click the Code Review button, and that's going to take the active editor and blow it up to the full window, so that I can concentrate on the task at hand, just like Focus mode.

When I'm done, I click again, my layout comes back.

That is a quick whirlwind tour of some of the many workflow changes in Xcode 11.

Back to you Ken.

[ Applause ]

Thanks Brendan.

I love that new Minimap, by the way.

And there's so many other great Source Editor features this year from Spell Checking to Nested Code Folding to Inline Diff, just to name a few.

But one area in particular that we focused on over the last year is Code Completion and giving you better results in more places.

There's now Code Completions for Compiler Control statements and that never Completions work more reliably, and in more places like here, when you're pending an enum to an array [applause].

All right [applause].

And there's now Code Completions for function overload.

So these are just a few of the many Completions we've improved in Xcode 11.

Now, let's look at the Source Code Editor, and workflow.

Now, this is a huge year for Swift Package Manager.

It's been thriving since we introduced it with tons of packages available today, all of which let you build on the great work happening in the community.

The packages are a great way to factor your own code, breaking it up into smaller, more testable pieces.

Well, this year, we have fully integrated Swift Package Manager with Xcode.

You can use packages to build apps for all of the platforms.

[ Applause ]

And packages, get first class integration throughout Xcode, from Source Control integration, to debugging, to testing, everything that you do with packages, it works just like you're used to, with projects.

And Xcode makes it easy to discover and use packages, and then just as easy to create and share your own with the world.

The integration with multiple services means that you are only ever just a few clicks away from some awesome code.

We really think you are going to love using Swift Packages.

And here to show you how to get started with Swift Packages in Xcode is Patrick.

[ Applause ]

Thanks Ken.

Today, I'm really excited to show you all Swift Packages in Xcode 11.

I will be working on our travel app, which includes a trip planning feature.

This feature right now doesn't have any weather information which is a pretty important part about any trip.

I don't want to have to reinvent the wheel to get this information in my app.

Lucky for me, my coworker Rhonda told me about a package that I could use to do just this.

So, let's add it to our project.

I'll start by navigating to the Project Editor.

And I'll navigate to the project where I'll see a new Swift Packages tab.

This tab will show me any packages that my project currently depends on.

To add the first, I'll click the plus button.

And because I've already logged in with my GitHub account, I can see all of my personal packages, organizational packages, as well as my starred repos right at the top Here's that forecast package I was talking about.

So, if I click next, Xcode will prompt me for my version information here, and Xcode will automatically fill in the most recent up-to-date version for me to start using.

And that's what I want because I want the most up-to-date code, right away.

When I click next, Xcode will resolve any dependencies that my package may have, but because it's this pretty simple package, it doesn't have any dependencies, it will resolve right away.

Finally, I need to choose which target to link my package product against, and I'll choose my app target here, and I'll finish up.

So, that was it.

All I had to do to set up my package in my project was to add it to this dependency section.

[ Applause ]

And over in the project navigator, I now have a Swift Package dependency section, where I can browse all of the source of this package, just like it were part of my project, because it is.

Great. So, I have a pretty good idea of where I need to implement this functionality.

I'm going to put it right in my Weather Fetcher Swift file here, which currently doesn't do a whole lot.

Now that I've configured it, I can quickly import the forecast module.

And I'll start by creating a Forecast Object using the region that was passed in.

But I just grabbed this package on GitHub and I'm not very familiar with the API.

I could go look at it on the web, but because of the first-class citizen right here in Xcode, I can quickly jump to its definition and start browsing its source right away.

So, I'll scroll down a little bit.

And this observations method looks like what I want to use.

But I'm not familiar with this observations structure this type.

So I want to I want to jump in and find out more about it as well.

And to show off some of our new search functionality in Xcode 11, I'll use the find navigator by using command shift F.

And I'll navigate down to the Forecast Package here to narrow my search just into that Forecast Package.

I'll search for observation, and I'll only get results for that package.

And it looks like it's defined right here.

OK. So this enum looks like it has different options for me, like the metrics that will come back from this API, like the high temp, the low temp, the precipitation, and so on.

I only want the high and low temp for my method, so I'll go and use those.

And I'll use command shift J, to jump back to the project navigator, and navigate back to the Weather Fetcher here, and I'll start implementing this method.

So, I'll use my Forecast Object.

I'll pass in the date that was passing to this method.

And like I said before I want the high temp and the low temp.

And I'll fill in my Completion Handler really quick, grabbing the high and low temp out of the results, and then calling the completion with high and low.

I'll fill in the condition method in a very similar way, only grabbing the condition back from the results.

Awesome. So, now when I build, and run, and review the results in the simulator, I should be able to navigate the Plan tab and see some weather information in my San Francisco trip.

And it looks like I got the high and the low and the expected conditions.

And it looks like it's going to rain right towards the end of my trip, so I should probably bring a jacket.

It was that easy to configure a Swift Package dependency in my project and start using it right away.

That's the weather.

Back to you Ken.

[ Applause ]

Thanks, Patrick.

[ Applause ]

Now, all of that new package integration is built on top of Xcode Source Control Support, and this year we're rounding that out with a couple more features, starting with Git Stash, which lets you save off a set of your changes.

[ Applause ]

It's available right here from the Source Control menu where you can quickly stash your current set of working changes.

When you want to review those changes and pop the stash you can do that from the Source Control navigator.

We're also integrating Cherry-Pick from the Source Control history view here, or just bring up the context menu on a comment and choose Cherry-Pick.

So, it makes it really easy to move changes between branches.

And like I mentioned earlier, you can now get the Source Control history for any file, anytime, with the new History Inspector, which by the way works great for non-tech files too.

[ Applause ]

Yesterday you saw the introduction of a number of new OS features, and you can begin adopting those today.

Once you bring your iPad app to the Mac.

You can start customizing it using the new Mac device here in the Storyboards Devices bar, makes it quick and easy to make your app feel right at home on the Mac, and for the new iOS dark appearance.

This system does a lot of the work for you.

Again, using the devices bar you can quickly switch between light and dark and make sure that your app looks great.

Now, all of the new SF symbols are fully integrated.

The options you need are right here in the inspector, things like having the symbol size, track the system font size.

And then when you want to browse all the symbols, you can do that in the redesigned library, and then drag them right out into your Storyboard.

Now, for your own resources, things like colors, and images, Asset Catalogs, they play a really important role.

They let you vary for things like device type and for light and dark.

The best part is, you don't have to write any code to do that.

In Xcode 11, in iOS 13, you can create your own custom symbols.

They get all the great characteristics of the new SF Symbols.

So, symbols, they let you specify various sizes and weights of artwork.

And then at runtime, the system, it'll choose the right variant, based on things like the users' font size, accessibility settings, even where the art is used within the user interface.

So this is a really powerful new way to create dynamic artwork.

And in Xcode 11, you can localize assets now too.

You just select an asset, click the Localized button and the Attributes Inspector, and choose the localizations that you want to customize.

[ Applause ]

Very important stuff.

And here to show you the updated Design tools is Lisa.

Thank you, Ken.

Hi, everyone.

Today, I'm excited to show you how to adopt the new iOS 13 features, Dark mode, and SF Symbols.

Let's work on the login view of our travel app.

The two images here, email and password are now using custom images.

I would like to change to use the SF Symbols, so that they look great and they can work with dynamic type.

When I browse the library earlier, there are two images that look nice to me.

One is called envelope the other is lock.

So let's change to use them.

First, I'm going to click the email icon, and open the inspector.

In Xcode 11, in the email, in the our image icons here that I cannot only view, the image names, but also I can see their appearances before I choose to use them.

So I'm [applause].

Yeah, like that too.

So, I'm going to type envelope.

Now it will show me a list of envelope with different appearances.

I'm going to select envelope.fill, which looks good.

And for the symbol configurations, I would like to set as font, so that they can work with dynamic type.

I can also change the font size.

Let's change to a bigger one.

Title One.

Next, I would like to do the same for the password icon.

I'm going to type in lock and choose lock.fill which matches the style here.

Again, I'll set the configuration as font.

Next, I would like to take a look how my view looks in the Dark mode.

From the devices bar there's a switch I can change from light to dark, let's do it.

Now you can see the view has been updated.

However, this image doesn't look right.

The handle of my suitcase disappears.

Let's figure out what happened.

I'm switching back.

Oh, I see.

The handle is black.

So, it doesn't show very well against the dark background.

To fix that, I would like to provide a new variant for this image for the Dark mode.

Luckily, I have a great designer named At.

He has already created one image for me to use in dark.

Let's change to use it.

I'm going to select the image.

And I can click this arrow.

It will open this image into dark appearance.

First, let's enable the dark appearance.

And then I can drag in the image, created by At.

Let's change by, up to the Storyboard.

Now, you can see in Light mode, it is still using the original image as expected, but when I changed to Dark.

Now the new image has been using, it's look good.

[ Applause ]

But At is a perfectionist, he thought these two blue buttons, although they look good in Light that he feel it doesn't pop as much as he wants in Dark.

So, instead, he wanted me to change to use a different color orange.

Let's figure out how to do that.

I'm going to select the button.

And now, I can see the tint color is set to use a custom color called Button color.

So to use a light in the Light mode, I would like continue to using the blue button, but actually in the Dark mode, I would like to change to use the orange color, just as easy as what I done for the image.

I'm going to open in the inspector and enable the dark appearance.

And for the dark appearance, I'm going to use orange color.

Let's switch back.

Cool. I do find these two-orange button pop more and look better now.

Next, I would like to take a look how my view looks at runtime.

So, I'm going to build and run in a simulator.

In Xcode 11, there's a new feature called Environment Overrides.

It is located in the Debug bar.

When I click it, it will show me a pop over that I can change different settings, such as system settings and accessibility settings.

So, I can change the interface style from light to dark to see how my view got updated.

I can set different accessibility settings, for example, the bold text.

From this overrides, it allows me to test out my app at runtime with these different settings, without actually changing the settings on my simulator or devices.

I can [ Applause ]

I can also change the dynamic type size by dragging the slider here and you can see how the view has been updated.

[ Applause ]

Remember earlier when I said the SF Symbols for these two images that I used font for their configuration.

So, now, when I'm dragging to set different dynamic type, they react to it, just like text.

With very simple edits, I think my view looks great in iOS 13.

I hope this can make your app look great as well.

Thank you.

Give it back to Ken [applause].

Thanks, Lisa.

These new dark iOS apps look fantastic.

And some of the scenarios that your users run into on their devices, things like networking or thermal conditions.

Those are really hard to reproduce.

And that makes them really hard to debug, well, in Xcode 11 you can change the way your device behaves, varying things like the network throughput, or changing the device's thermal state.

In the devices window there's a new Device Condition section where you can turn on the Network Link Conditioner and simulate real world networking scenarios, or you can turn on the Thermal State Conditioner.

Change your device's thermal state, so that it behaves like it's warmer than it actually is.

And once you turn on one of these conditions, you'll see an indicator on your device, and you can tap that indicator to see exactly which condition is running.

And you can stop it here, or when you disconnect from Xcode, it'll automatically be stopped for you.

This is a great way to make sure that your apps perform really well in all conditions.

Xcode 11 continues to improve testing this year with the introduction of test plans.

Now test plans let you define a set of tests that you can share across schemes.

A test plan can have any number of configurations that let you say what arguments do you want to pass or what environment variables do you want to say, even what sanitizers do you want to turn on?

When you run that test plan, it runs all the tests in all the different configurations.

So, for example, you can have a test plan that has configurations for each language your app supports.

When you run that test plan, it runs all the tests in all the different languages, all with just a single action.

And, of course, test plans, they work great with the Xcode's server where you can run your tests on multiple devices and simulators, all in parallel, and now in more configurations than ever.

And it goes without saying, testing, it works great for iPad apps on the Mac, as well as those built with SwiftUI.

And that's testing.

There are some awesome improvements to the simulator this year.

There were the new standalone watch apps you can deploy directly to the watch simulator.

No iPhone simulator needed.

[ Applause ]

But the big news this year is that the simulator is built on top of Metal [ Applause ]

Yeah.

[ Applause ]

So that means that apps built using Metal can now run in the simulator, and they get amazing graphics performance, and everything that's built on top of Metal, like UIKit, well, that gets a whole lot faster too.

You'll see a beautiful 60 frames per second.

And CPU use, it is reduced by up to 90% which is really great for battery life [applause].

Yeah.

[ Applause ]

We didn't stop there though.

Simulator Warm Boots are now up to twice as fast too.

[ Applause ]

So, big improvements to the simulator.

Last year we introduced, OS Signposts and Custom Instruments, so that you can surface your own data up through the tools.

Well, this year, we're bringing hierarchy to the tracks, to make it easier for you to explore and correlate data.

But when you use OS Signposts each category that you log, will now get its own track, like this.

Then you can pin that track and easily correlate it to another track, like CPU use.

We're also introducing a new template for SwiftUI to give you insight into how much time you're spending building your user interfaces in the new body methods.

And we've completely rewritten the Metal System Trace Template from the ground up.

It takes advantage of the new hierarchical tracks and it's significantly faster, up to 10 times faster.

Now, we can't finish up here today without talking about SwiftUI, which really is an amazing new way to build user interfaces.

SwiftUI makes it seamless to move from editing to running to debugging.

The new previews which show you your real UI, they make these three things, just a single activity.

Editing, when we see this is the future of UI development.

So, from the new Preview mode to the inline editors, we've rethought how to build UI code.

And we've done that with an eye towards efficiency and direct manipulation, so that you can write more code without ever typing a character.

And there's a brand-new documentation experience to go with it.

And that's going to get you up and writing code quickly.

There are great new tutorials, all which guide and teach you, while helping you write code.

Now, you don't need to create a new project to get started with previews, you can use them right in your existing apps, just implement the new UIViewRepresentable protocol and hand back one of your own views.

It's really that easy.

So, whether you have an iOS, macOS, watchOS, or tvOS app, you can get started today.

Well, that is a look at Xcode 11.

Thank you very much.

Have a great conference.

[ Applause ]

Apple, Inc. AAPL
1 Infinite Loop Cupertino CA 95014 US