>> Ken Orr: Good morning. >> 肯·奥尔:早上好。
[applause] [掌声]
>> Ken Orr: Xcode 7 is our next major release of tools >> 肯·奥尔:Xcode 7是我们的下一个主要版本的工具
for building Mac, iPhone, iPad and Apple Watch apps. 去构建 Mac, iPhone, iPad 和 Apple Watch 应用。
Let's get started this morning and take a look 今天早上我们开始吧,看一看
at what's new in Xcode. 在Xcode中有什么新东西。
The biggest news this year is that we've added support 今年最大的新闻是我们添加支持
for a third platform, Watch OS, and of course, 第三种平台,手表系统,当然了,
you can build Apple Watch apps right 您可以构建苹果看应用程序
in the same great Xcode tools that you already know. 用同样伟大的Xcode工具,你已经知道。 WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
Xcode 7 also includes Swift 2, Xcode 7 还包括 Swift 2,
building on the new programming language we introduced 这个在我们介绍的新的编程语言
last year. 在去年。
Swift 2 is faster across the board, Swift 2 非常快，
not only will your apps run faster when you're running 不仅将当你运行你的应用程序运行得更快
and debugging in Xcode, more importantly, 和在Xcode中调试更快,更重要的是,
they'll run faster on customer devices. 客户设备上他们会跑得更快。
Swift 2 also includes a number of new language features, Swift 2 还包括一些新语言特性,
like Error Handling which introduces an explicit syntax 像错误处理,引入了一个显式的语法
that makes it much more natural to deal with errors in Swift. 使它更自然在迅速处理错误。
Availability, Swift now has insight 可用性、Swift 现在有洞察
into the minimum OS required for particular API, making it easier 到所需的最小操作系统特定的API,使它更容易
for you to adopt new API 采用新的API
and also maintaining support for existing OSs. 和维护支持现有的OSs。
Testability. 可测试性。
Test bundles can now see internal API, 测试包现在可以看到内部API, WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
letting you get broader test coverage without having 让你得到更广泛的测试覆盖率在没有
to expose anything additional in your sources. 曝光任何附加在你的源码。
Protocol Extensions lets you add methods to any type 协议扩展允许您将方法添加到任何类型
that implements a particular protocol. 实现一个特定的协议。
You can convert all of your Swift code 你可以把你所有的 Swift 代码
to Swift 2 using Xcode 7's Migrator. 使用 Xcode 7 的迁移工具迁移到 Swift 2。
It works great for projects as well as playgrounds. 它适合于项目以及 playgrounds。
We have also added a couple of new language features 我们还添加了一些新的语言特性
to Objective-C to make it work even better with Swift. 在 Objective-C,使其能与 Swift 更好的工作。
Like Generics which let you specify type information 像泛型让你指定类型信息
for collections. 的集合。
Also Nullability Annotations which let you specify 还 Nullability 注释允许您指定
when you expect something it to be nil or non-nil. 当你期望它可能为 nil 或非 nil 值。
In Objective-C which makes it really seamless when you want 在 Objective-C 中,使它真正无缝的,当你想要的
to interact with options in Swift, really nice. 与 Swift 中的可选值互动,真的很不错。
We have gone ahead, we have adopted all these language 我们已经提前,我们采用了所有这些语言
features in our own SDKs. 功能在我们的sdk。 WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
So you will start seeing the benefits today. 所以你会看到今天的好处。
Now, if you want to get started with Swift 2 or maybe some 现在,如果你想开始 Swift 2 或者一些
of those new APIs you saw yesterday, 你昨天见到的新的api,
well there's no better place to do that than in the playground. 也没有比 使用 playground 更好的地方。
We introduced playgrounds last year 去年我们介绍了 playgrounds
and they have come a long way since then. 从那时起,他们已经走了很长的路。
Not only can you explore and play with code, 不仅可以探索和实时预览代码效果,
but now you can explain an idea or a concept all 同时，你可以解释一个想法或概念
from within a playground. 在一个 playground。
We have introduced features like Rich Comments 我们引入了功能丰富的注释
which let you explain what's going 这让你解释什么
on in the surrounding code using a simple mark-up syntax. 在代码的周围使用一个简单的标记语法。
They have beautiful formatting and fonts 他们有漂亮的格式和字体
which really help them stand out. 这让他们脱颖而出。
Within these comments you can include things like web links 在这些注释可以包括 web 链接
or lists or even images. 甚至列表或图像。
We have also made it possible to pull results which were shown 我们也能把结果显示 WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
in quick-look popovers, you can pull them right 在快速浏览弹窗,你可以把它们正确的
into the source code under the line 进入到源代码之下的行
of source that generated them. 生成它们的来源。
This really helps tie the cause 这真的帮助领带的原因
and the effect much more closely together. 和影响更紧密地结合在一起。
This is really nice. 这是非常好的。
You can add almost unlimited functionality to a playground 您可以向一个 playground 添加无限的功能
by adding Swift code to the new supporting sources folder. 通过将 Swift 代码添加到新的支持代码文件夹。
This helps you keep your playground clean 这有助于你保持你的 playground 干净
and focused while also giving you a place 专注，同时也给你一个地方放
to put the supporting functionality. 功能支持。
There is also a performance one here 还有一个体现在这里
because the supporting sources, they can be compiled 因为这个支持源，它们可以被提前编译
down because they're not run interactively. 因为他们没有交互运行。
They're only there to support your playground 他们只在那里为你的 playground 提供支持
and that helps them run really, really fast. 和帮助他们运行非常非常快。
Our newest playground feature is Pages 我们最新的 playground 特点是 Pages
which lets you create content that progresses through a topic. 它可以让你通过一个主题展示创建内容的过程。
For example, if you wanted to author a playground 例如，如果你想创作一个有关排序的 playground WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
about sorting, you could add an introductory page that went 你可以添加一些介绍页面，
into the fundamentals of sorting 到排序的基本原理
and then you could add subsequent pages 然后你可以添加 后续页
that covered things 包括
like specific sorting algorithms quick sort, bubble sort. 特定的排序算法，比如快速排序，冒泡排序。
Then, when you wanted to provide navigation through the pages, 然后，当你想通过 pages 提供的导航，
you can add some of the new mark-up syntax we 你可以添加一些新的 标记 语法
have introduced. 我们之前介绍过的。
Playgrounds are a powerful way to teach. Playgrounds 是一个强大的方式来教。
Last year we introduced the guided tour as a playground. 去年我们推出了指引作为一个 playground。
This year we have updated it to use Pages. 今年，我们已经更新了其使用的页面。
That's Swift 2 and the new playgrounds. 是 Swift 2 和 新的 playgrounds。
In addition to iOS 9 and OS 10 El Capitan we have added sport 除了​​ iOS 9 和 OS 10 埃尔 卡皮坦 我们增加了运动
for Watch OS 2. 手表 OS 2。
The new WatchKit will help make your apps more responsive, 新 WatchKit 将有助于使你的应用程序反应更灵敏，
but it also gives you more control 但它也给你更多的控制和 WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
and flexibility as a developer. 灵活性，作为一个开发者。
If you haven't already, I encourage you to check 如果你还没有准备好，我鼓励你看看
out What's New in Watch OS 2. 什么是新的 Watch OS 2。
Some really nice stuff. 一些非常好的东西。
You can build your entire watch app, of course, 您可以的构建整个手表的应用程序，当然
right in Xcode using storyboards where you can quickly lay 在Xcode中，使用故事板让您可以快速制定出
out how your app will flow from screen to screen. 如何使你的应用程序会从一个屏幕流到（过渡）另一个屏幕
You can design and implement glances 你可以设计和实现总览，
or even the new WatchKit complications. 甚至新的 WatchKit 并发。
For iOS, using things like the new StackView it never was 对于iOS系统中，使用像新 StackView 它永远不会是
更容易地创建一个通用的应用程序去处理一些事情，
such as changing screen orientation 比如改变屏幕方向
or different screen sizes. 或不同的屏幕大小。
With the new iPad multitasking, size classes which you define 随着新的iPad的多任务处理，size classes
in interface builder, they have never been more important. 你在Interface Builder 定义，他们从未如此重要。
Along with iOS 9 we're introducing a new crosscutting 随着 iOS 9 我们推出新的交叉
feature called App Thinning. 功能称为 App 瘦身。 WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
The App Store can tailor your app to deliver the best, 应用程序商店可以根据您的应用程序提供最佳的，
smallest possible version to each unique customer device. 最小的版本针对每一个独特的客户设备。
This will let you focus more on building a great app 这将让你更专注于建设一个伟大的应用程序，
and worry less about size because you will know 不用太担心的大小，因为你会知道
that customers, they'll never download bits they won't use. 客户，他们永远不会下载自己不会使用 bits(字节，应该是不用的数据吧！)。
Xcode of course has great support 当然Xcode中提供了很大的支持 ，
to help you configure how your app will be thinned. 以帮助您配置如何您的应用程序将被瘦身。
There are three separate parts to App Thinning, 有三个独立的部分去为 App 瘦身。
starting with Bitcode. 先从 Bitcode 开始。
When you archive for submission, Xcode compiles your app 当你提交存档，Xcode的编译你的应用程序
down into an intermediate representation called Bitcode 分解成叫做 Bitcode 的中间表示，
which gets sent to the store. 它被发送到商店。
The App Store can later re-optimize your binary, 该应用程序商店可以在以后重新优化的二进制文件，
helping you future-proof for things like compiler updates 帮助您面向未来的东西像编译器的更新
or even new processer capabilities. 甚至新的 processer 能力。
To take advantage of Bitcode you don't actually have 要利用 Bitcode 你实际上并不需要
to do anything. 做任何事情。 WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
Xcode will do all the hard work here. Xcode 会处理所有的困难工作。
The second, there is Slicing. 第二，就是切片。
When the App Store goes to send your app 当应用程序商店去把你的应用程序
to a customer device it will only include artwork that's 发送给客户的设备，它将只包括原图
needed for that particular device. 给需要特定设备所需要的。
For example, if you have both 2x and 3x artwork in your app 例如，如果你同时拥有 2x 和 3x 在您的应用程序
for an iPhone6 and a 6+ the iPhone6 will only get the 2x 为 iPhone6 ​​和 iPhone6 plus，iPhone6​​将只能得到 2x 原图
artwork and the iPhone6+ will only get the 3x artwork. 而 iPhone 6​ plus 将只能得到 3x 的原图。
To take advantage of Slicing, all you need 为了充分利用分片，所有你需要做的是
to do is use Asset Catalogs in Xcode. 在 Xcode 使用资源目录。
Third, on-demand resources, which let you control 第三，请求式（按需）资源，让你控制
when assets are downloaded. 下载资源时。
For example, you can start downloading level 5 例如，你可以开始下载游戏的第 5 关
of your game just as the user is finishing up level 4. 当用户完成了第 4 关。
It gives you a ton of control. 它给你很多的控制。
Really nice. 真的很好。 WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
Here to give us a demo of Watch OS 2 and App Thinning is Jon. 这里给大家演示 关于 Whatch OS 2 的 Demo 和 App 瘦身的是 乔恩。
>> Jon Hess: Good morning. >> 乔恩·赫斯：早上好。
Today I would like to show you two of my favorite new features 今天，我想告诉你两个我最喜欢的新功能
in Xcode 7; native-watch extensions 在 Xcode 7 中; 本地手表扩展
and application thinning. 和应用瘦身。
Let's get started with our trivia game project. 让我们开始与我们的琐事游戏项目。
Now in our trivia game we already have things set 现在，在我们的问答游戏，我们已经拥有的东西设置
up for WatchKit 1, and right now I want 为 WatchKit 1，而现在我想
to update it to Watch OS 2. 更新它到 Watch OS 2。
It looks like Xcode has the same idea. 它看起来像 Xcode 中有同样的想法。
Here in the navigator, I can see a project modernization sequence 在这里，在导航器，我可以看一个项目的现代化序列。
already queued up for me. 已经为我排队
I going to go ahead and select it 我要继续，然后选择它
and begin migrating myproject settings to Watch OS 2. 并开始迁移我的项目设置到 Watch OS 2。
Here in the panel, Xcode gives me a brief overview 在这里，在面板上的 Xcode 给了我简要概述。
of everything that's going to happen. 关于一切将要发生的
I would like to go into it with more detail for you. 我想进入它给你更多细节。
Just like Watch OS 1, Watch OS 2 applications are composed 就像 Watch OS 1，Watch OS 2 应用程序是由
of an app extension and application. 一个应用程序的扩展和应用程序。 WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
Your code goes in the app extension 你的代码放在应用程序扩展
and drives the app remotely. 和远程驱动程序。
New in Watch OS 2, both the app extension 新的 Watch OS 2，无论是应用程序的扩展
and the app run directly on the watch. 还是应用程序都直接运行在手表上。
This allows our applications 这使得我们的应用程序
to be more responsive and independent. 能更好的响应性和独立。
Sounds great. 听起来不错。
I want to perform these changes. 我想执行这些改变。
What just happened? 刚刚发生了什么？
Xcode took care of the details Xcode中注意到一些细节。
of migrating my project settings to Watch OS 2. 关于迁移我的项目设置到 Watch OS 2。
It configured my Watch targets to build 它配置了我的 Watch 目标，以建立
against the new Watch OS SDK that we released yesterday, 对新观察OS SDK，我们昨天公布，
it set their minimum deployment target to Watch OS 2 其设置其最小的部署目标 Watch OS 2，
and it configured my Watch app extension to be copied inside 它配置我的 Watch 的应用程序扩展内部的复制
of my Watch app so that when they're installed 我的 手表 应用程序 当正在安装
on the Watch itself they both go over together. 在手表本身他们俩在一起。
All right. 好吧。
That's everything with upgrading my project settings 这是所有关于升级我的项目设置
to Watch OS 2. 到 Watch OS 2。
Our Watch application is nice and light, 我们 手表应用 好而轻，
but our iOS application is a quite bit bigger. 但我们的iPhone应用程序是一个比较大一点。
It is mostly due to all of these images in my asset catalog. 这主要是因为在我的资源目录这些图像。
I want to make it smaller but don't want 我想让它小，但不想
to remove any content. 删除任何内容。
This is where the new App Slicing feature comes in play. 这是新的应用程序分层功能，自带的播放。 WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
You see every one ever these images has a 1, 你看，每个人都曾经这些图像有一个 1
2, 3x representation? 2，3x 表示？
Well with App Slicing, Xcode 7 and the App Store are going 那么对于 App 切片，Xcode 7 和 App Store 要
to work together to make sure 共同努力以确保
that each device just gets this single image that best suits it. 每个设备只是得到一个最适合它这种单一的图像。
This cuts 30- to 40 percent off the size of our application 这样可以减少我们的应用程序 30〜40％ 的的大小，
and the best part is it's pretty much automatic. 并且最好的部分是它几乎是自动的。
All I need to do is use Xcode 7 in an asset catalog 所有我需要做的是使用Xcode中7在资源录 ，
which I'm already doing. 我已经在做。
What about the other assets you would 你会怎样处理其他资源
like to target for each device. 你想要为每个设备的目标。
We have extended the asset catalog in Xcode 7 我们在 Xcode 7 扩展了资源目录，
to support arbitrary data. 去支持任意数据。
You can put whatever you want in here. 你可以把任何你想要在这里。
Down here further in the catalog, 在这个目录中，
I have this skylines folder. 我有这样的 地平线 文件夹。
It's filled with 3D models of cities from around the world. 它充满了来自世界各地的城市的3D模型。
We present them to the user and they guess 我们将它们展示给用户，他们猜测
which city they are looking at. 他们在看哪个城市。
San Francisco, I have a really high-quality model of the city 旧金山，我有一个真正高品质的模型
of San Francisco I would like to include in our game, 关于旧金山市 ，我想在我们的游戏加入它
but I only want to send it to the most high-end devices. 但我只想把它发送到最高端的设备。
No problem. 没问题。 WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
Just like images can vary by scale factor and size class, 就像图像可以通过比例因子和大小各不相同的类，
data assets can vary by device performance characteristics, 数据资源可以通过设备的性能特点，
things like the amount of memory on the device, 诸如此类的存储器设备上的量，
or the GPU capabilities. 或GPU的能力
I want to add a specialization for machines 我想添加一个专门的机器
with 2 gigabytes of memory. 它有 2 GB 的内存。
Then I will just go ahead and drag 然后，我只是继续和拖
in my high-end resource and I'm good to go. 到我的 高端 资源，我。
Each device will get the resource that best suits it 每个设备将得到最适合它
without double-paying. 没有 2 倍 资源。
All right. 好吧。
Now I would like to show you on-demand resources. 现在我想向您展示 请求式（按需） 资源。
On-demand resources allow us to host the content 请求式（按需）资源，让我们能够远程托管
for application remotely on the App Store. 应用程序在应用程序商店上。
We opt our resources in to on-demand hosting 我们选择我们的资源，以 请求式（按需） 托管 。
by tagging them with strings. 用字符串标记他们
The strings can be anything we want. 该字符串可以是任何我们想要的。
For example, if we're making a game, we might tag each 例如，如果我们做一个游戏，我们可以标记每个
of the assets that comprise one 资源，它们组成
of the levels by that level's name. 关卡由该关卡的名称之一
Then, at run time, we use the new NS Bundle Resource Request 然后，在运行时，我们使用了新的 NS 包资源请求
class to fetch and pull down whole tags worth of content 的类获取并拉下身价的内容全部标签
into our game for fast, local access. 到我们的游戏中快速，本地访问。
Let me show you how to get started 让我来告诉你如何开始使用 WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
with on-demand resources. 请求式（按需）资源。
Here I've selected a folder in the catalog. 在这里，我选择在目录中的文件夹。
It represents all of the questions 它代表的是所有这些的问题
in the world genre of the game. 在游戏的世界风格。
In the inspector I'm going 在 inspector 我将
to use the new on-demand resource tag section 使用新的 按需 资源标记部分
and tag this content, world questions. 和 标记这个内容，世界问题。
I've just opted all of it in to on-demand hosting. 我只是选择了这一切到按需托管。
Now, what kind of things can you tag in a catalog? 现在，你可以在一个目录标记是什么样的东西呢？
You can tag entire folders like I just did. 就像我只是做了你也可以标记整个文件夹。
You can tag images and data assets directly, 您可以直接标记的图像和数据资源，
您还可以在资源目录标记 Sprite Atlases（精灵地图集）。
Sprite Atlases are a new component 精灵地图集 是一个
of the Asset catalog in Xcode 7. Xcode 7 资源目录的新组件。
By putting your Sprite Atlases in the catalog, 把你的精灵地图集放入目录
it makes them eligible for the Splicing feature I 这时的他们能有分片功能的资格
mentioned earlier. 前面提到的
You can also tag loose files in your Xcode project. 也可以在你的 Xcoxe 项目中标记松散的文件
This inspector gives me a great overview of all 属性介绍几种给了我一个很好的全局概览
of the tags on a particular file. 关于特定文件的标签
What if I want to see all the files in a tag, 如果我想说的文件在一个标签里面会怎么样
or just all the tags period. 还是所有的标签
For that, I can head over to the Project Editor, 为此我可以去项目编辑器
by selecting our Application Target and going 通过选择我们项目的目标,然后
to the New Resource tag section I can see all of my tags. 到新的资源标签部分,我就能看到所有我的标签 WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
As you see, I tagged a lot of content earlier. 如你所见,我之前的标签
It is a great place to get an overview 这是一个很好的概览
and make sure things are consistent like I expect. 并且所有的事和我预想的一样
For example, I see this books tag doesn't match the format 例如,我看到这个书的标签格式不匹配
of the others, they all have this question suffix. 和其它的，他们都有同样的问题后缀
No problem. 没问题。
I'll edit this, and update all the content in one go. 我编辑然后更新一下它的内容
Now with tag to all of our content for on-demand resources, 现在用标签标记所有的内容为按需资源
and I would like to show you how to started using it from code. 我用代码演示怎么开始使用它
That's where the new NS Bundle resource request class comes 这就是 NS 包请求资源类
into play. 发挥作用
Here in our game class, we have two callbacks 这样的游戏类中，我们有两个回调
that will be perfect for this, 这张是完美的
start using genre and stop using genre. 开始使用类型和停止使用类型
Two reasons they are great for using on-demand resources first, 有两个原因是他们非常适合使用按需请求，首先
they are bracketed in time, and second, 他们是相等的，其次
they happen a just a bit before the user actually initiates the 他在用户真正开始游戏之前
game but as soon as when we know what they're going to play 一旦我们知道他们将要去玩
in the game, It lets us pre-fetch the on-demand content. 在游戏中，我们一向获取需要的内容
I'll get started with an instance variable 我将开始一个实例变量
to hold an NS Bundle resource request. 保存 NS 包资源请求
NS Bundle resource requests are substantiated from tags, NS 包资源请求从标签证实 WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
and remember, tags are just simple strings. 然后记住,标签都是一些简单的字符串
I'll use our genre's name with batch questions appended
to the end to form our tag.
Then I can create the bundle resource request from that tag.
Finally, I can invoke the request
with the new begin accessing resources
with completion handler method.
This is an asynchronous method that runs in the background.
It downloads all the content from the store,
and when it's done, it fires my completion handler.
Once my completion handler runs, and until I say I'm done
with the resource request,
I have fast local access to all the content.
This is my favorite part.
I get it all, that content with the same APIs I'm already using.
Methods like NS Bundle, Path of Resource, UI Image, Image Name,
Texture, Texture Name, all continue
to work exactly as they did before.
I'm not making any changes to the rest
of the resource lookout code throughout my application.
Now, I set all that content as available until I say I'm done WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
Now, I set all that content as available until I say I'm done
with the NS Bundle resource request.
How do I do that?
In our stop using genre method,
I'll invoke end accessing resource
on the NS Bundle resource request.
This moves all the content that I fetched into the cache
so it is available for future access but it also marks it
as available for purging in the even
that the system runs out of space.
With that, we have written all of the code we need
for on-demand resources.
I want to build and run our game.
We'll start a new game.
I'll show you some of the debugging functionality
for working with on-demand resources.
Here in the debug navigator, I'm going to select the disk gage
to bring up the disk report to get an overview
of all the ways the application is using the disk.
We've added a new section here in Xcode 7,
on-demand resource tags.
You see can see my tags, their size, and their current status.
All that are currently marked not downloaded,
Xcode is mimicking the role of the app store right now.
All of my resources are in Xcode, not on the simulator yet.
But, when I click one of these genres, WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
But, when I click one of these genres,
the code that we just wrote runs in the background,
downloads the content and now you see my tag is marked in use.
If I switch to a second genre,
you can see the first content is moved to the cache,
just marked downloaded, and now engineering questions are
in use.
That's Slicing and on-demand resources.
With Application Slicing, we're able to lower the size
of our iPhone 6 application from more than 140 megabytes
to less than 100 megabytes.
With on-demand resources we were able
to further lower the initial install size
down to just 30 megabytes.
Now users can get started with our game faster than ever.
Back to you, Ken.
[applause]
>> Ken Orr: Thank you, Jon.
This year we have introduced a number
of new features targeted squarely
at helping you enhance the quality of your app.
Let's start by talking about debugging and profiling. WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
Let's start by talking about debugging and profiling.
In Xcode 7 we have brought the energy gage to iOS apps.
IOS 9 contracts energy on a per process basis.
That's reflected right here in the energy report.
The gages in Xcode are a great way for you
to match what you expect to be happening
against what's actually happening.
If you see a spike in energy usage and you're sitting
in your app apparently idle, that's a first clue
that maybe you have a problem.
Sometimes when you have a problem like that,
you know exactly where to go looking in your code.
But when you don't, you can jump right into Instruments from all
of the reports in Xcode.
From the Energy report we can jump
into the New Location instrument which lets us make sure
that we're efficiently using core location APIs.
We can answer questions like are we asking
for the user's location too often, are we asking WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
for the user's location too often, are we asking
for the user's location with too high a precision?
Things like that are going to cost energy
and we can investigate those right here.
For iOS, this is also the new Metal System Trace instrument
letting you see how the frame rate is being effected
by things like your own code.
The graphics driver, hardware rendering, it gives you insight
into the entire Graphic Stack, really powerful.
You may also notice here in Instruments
that there is a redesigned track view.
It has a cleaner look,
more importantly it is more natural to use.
With gestures like pinch to zoom,
navigating through your data is really, really easy.
That's a quick peak at the new Instruments.
I'm willing to bet that every developer in this room has been WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
I'm willing to bet that every developer in this room has been
in a situation where a customer reports a crash
and you just can't reproduce it.
All right.
That happened once or twice maybe?
The new in Address Sanitizer in Xcode 7 can help.
Address Sanitizer compiles your Objective-C in C code in a way
that catch things like buffer overflows
and it can catch them immediately when they happen.
Xcode will stop you right on the line of code
that caused the problem.
This is a powerful new debugging feature.
Here to give us a demo of Address Sanitizer is Kate.
>> Kate Stone: Thank you, Ken.
Our trivia game is a great diversion with friends
but some are experiencing crashes
when they're setting up a game.
It is unpredictable enough that it is the kind WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
It is unpredictable enough that it is the kind
of bug that's hard to reproduce and make heads or tails of.
I'm sure you experienced something similar
as I've heard anywhere you have used pointers
to explicitly managed memory.
Our game is looking beautiful.
We can dive on in, start a new game, pick a genre,
pick a few users to work with and we're ready to play.
So it seems to work just fine -- oh.
Being on stage is perfect to reproduce this.
Hard to find bugs.
So let's have a look at this.
It's crashed, where is it crashed?
What can I debug?
It's crashed in my main class.
So there's not even I line of code I've written there.
There's nothing in the Stack Trace
to give me a place to start.
That's typical of this kind of bug.
Luckily, Address Sanitizer can help there.
We have a variety of these diagnostic tools
that you can get to from Xcode.
All you need to do is go
to the Scheme editor for running your app. WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
to the Scheme editor for running your app.
As that handy shortcut, I'll hold down Option while I click
on Run to get to the Scheme Editor.
I can configure how I run my application here,
including the Diagnostics tab
which lets me select some potentially familiar tools
as well as the new tool, Address Sanitizer.
Enabling Address Sanitizer does something different
in that it recompiles the application adding a bunch more
Instrumentation showing me not just where I failed
but why I failed as well.
Let's rerun that application and see how this works.
Now I'll find when I select a genre and move
to the next page it immediately stops my application
because this is where the memory corruption actually occurred.
Far before the application finally comes
to a screeching halt I can find out what went wrong.
In this case I get the exact Stack of where it stopped
and it turns out that it is some Objective-C code
that I'm calling.
Not everybody has the luxury of writing everything in Swift. WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
Not everybody has the luxury of writing everything in Swift.
In fact, in our case, we have this C code that's been wrapped
in an Objective-C framework.
That's the source of our problem.
I'm not familiar with this code.
I'll have a look at the code that I'm calling it
from written in Swift.
Here I am calling some logging API.
That tells me where exactly I'm triggering the failure
but still not yet why.
If I look further down the Debug navigator though,
I can see that in addition to Address Sanitizer telling me
that I'm using deallocated memory
and that that's the actual source of my problem.
I can also see in the Debug navigator what memory that is.
I'm accessing the first bite in a 50-bite heat region
that was previously allocated.
I can go a step further, click on and actually see the memory,
and see it has been previously used to store a log message.
Because it is gray, Address Sanitizer is telling me
that it knows that it is no longer valid memory,
no longer memory I should be accessing. WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
no longer memory I should be accessing.
It also gives me the call Stack,
where that memory was originally allocated and I can see
that it is when I'm creating a usage log that makes sense,
and more importantly in this case,
where that memory was deallocated.
I can tell here that it is when I call end logging,
the particularly badly designed API.
I thought it was just to flush the log but it turns
out it takes down critical resources.
Let's solve that problem quickly.
I can take that line of code,
instead of calling it every time I log a message,
I'm going to call it only once during tear down.
Now Address Sanitizer rebuilds the application complete
with Instrumentation, still very snappy, still possible
to use it interactively, and I can get a step further.
It all looks good until it finds my next problem.
Because Address Sanitizer is not just about deallocated memory.
In this case it is telling me
about a heap buffer overflow similarly telling me WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
about a heap buffer overflow similarly telling me
about under flows and Stack memory that I'm overflowing
or under flowing, it is an extraordinarily powerful tool.
It's the kind of tool you should use
on your applications right now
to find all those lurking memory issues.
We tried to make that as easy as possible
because Address Sanitizer cannot only run
in this interactive form, but you can use it
with Xcode Servers so you can set up a suite of tests
with Address Sanitizer enabled and find those problems
when they creep in your code.
Because you want to minimize the number of crashes
but let's be realistic, you can't eliminate them entirely.
So I'm proud to bring up Itai to talk
about how Xcode helps you analyze those crash logs you
will get.
[applause]
>> Itai Rom: Thanks, Kate.
Good morning, everyone. WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
As Apple developer program members you have access
to the new crash logs in Xcode.
When you distribute your app through the App Store
or TestFlight and include symbol information we'll collect crash
logs from your users.
Those crash logs will be fully aggregated into crash reports
and downloaded into Xcode wher you can view
and analyze them right in the organizer window.
The integration here is seamless making it easier
than ever before to find and fix your most critical issues.
I would like to show you how to use it.
Last year we introduced TestFlight.
TestFlight is a convenient service
for distributing beta builds of your apps and works great
with crash logs in Xcode.
We just distributed a beta build of our trivia game yesterday.
I'll like to find and fix some of the crashes
that our testers reported.
I'll launch Xcode.
I have already entered my Apple ID information
into Xcode's Account Preferences panel, so all I have to do
to view crashes is open the Organizer window. WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
to view crashes is open the Organizer window.
On the left side of the window, Xcode will download information
about all of the apps that my development team has uploaded
to iTunes Connect for the App Store or TestFlight.
I'll choose trivia.
On the right, I can choose which build
of trivia I'm interested in.
This build 55 at the top of the list is the one
that we distributed through TestFlight yesterday.
I'll click that.
Underneath Xcode will download information
about all of the top crashes.
These are sorted by frequency of occurrence, the one at the top
of the list is naturally the one
that our testers experienced the most often.
To the right I can see the back trace for this crash.
Xcode helpfully highlights one of the Stack frames
in a beautiful orangey salmon color,
that tells me something fishy is happening in my app.
In particular that's where my app crashed inside
of this usage log and log in method.
That looks similar to the crash that Kate just found WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
That looks similar to the crash that Kate just found
and fixed using the Address Sanitizer.
That's my favorite type of bug report, I don't have
to do anything since I watched her fix it.
I'm going to go ahead and mark it as resolved
by clicking this button on top of the window.
I can have Xcode filter out the crashes I have already resolved
by clicking the filter in the bottom of the window.
Now I can focus on the crashes that I still need to fix.
We have warmed up with a pretty easy one.
Let's take a look at the next crash.
This time we're crashing inside
of our splash screen view controller,
the beautiful landing page in the app where you see a grid
of your friends' images.
It looks like we're indexing into an array
and we might have indexed beyond the array's bounds.
I would like to try fixing this crash.
I can jump right into my source code by clicking the Open
and Project button, selecting my project, and then clicking Open.
Now, Xcode has not only opened my project,
it has also magically transported the crash log
that I was just viewing in the organizer right
into the Debug navigator where I can click through Stack Frames WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
into the Debug navigator where I can click through Stack Frames
and navigate through my crash log
and source code side-by-side.
It looks like we're crashing into the next image method.
This looks similar to a crash I think Jon came
to my office yesterday to tell me he was hitting.
What we're doing is indexing through an array of images
of our friends and incrementing a counter as we go.
When we get to the end of the end of the array,
we set the counter back to zero.
We have an easy to miss off by one error here.
This should be a greater than or equal to check.
I'll fix that.
It looks like you could hit this crash really easily
if you don't have very many friends,
which probably explains why Jon found it.
Now I can go back to the organizer and fix more crashes.
The new crash logs feature in Xcode
and TestFlight work great together to help you find
and fix your most critical issues before you ship
to your customers.
Now back to Ken.
[applause] WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
>> Ken Orr: Thank you, Itai.
Testing. Over the past few years we have continually added
to the testing support in Xcode.
Making it possible for you to test more
and more parts of your application.
In Xcode 5 we added a Test navigator.
When you combine that with the assistant editor we have a nice
workflow for test-driven development.
We have introduced XC Test our unit-testing framework,
along with Bots which let you automatically run the unit tests
on Xcode Server for continuous integration.
In Xcode 6, we introduced performance testing
to quickly let you identify performance regressions
and added testing for asynchronous APIs.
In Xcode 7, we're introducing User Interface testing.
The UI testing lets you test the part of the app
that users actually see and touch. WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
that users actually see and touch.
The tests like this are so important
because they help you ensure that your app continues
to function the way you originally intended.
Even as you make changes and enhancements over time.
Like all the testing features we have added to Xcode,
UI Tests work grade with Xcode Server.
This is particularly important for UI Test
because they may take a bit longer to run.
Also on Xcode Server you will oftentimes have access
to many more devices than you would at your desk.
This will let you get a broader range of coverage
and let you get that coverage more often.
Speaking of coverage, to round things out in Xcode 7,
we have added Code Coverage for testing.
You can turn on Code Coverage here in the Schemes Test action,
and when you do, Xcode will build your app
with special instrumentation that lets it track exactly
which lines of code are being executed. WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
which lines of code are being executed.
After you run a suite of tests,
you will notice the New Code Coverage bar here
on the right side of the source code editor.
This gives you a quick visual indication
that shows you exactly which lines of code were called,
more importantly it shows you which ones were not.
Here to give us a demo of UI testing in Xcode 7 is Joar.
[applause]
>> Joar Wingfors: Thank you, Ken.
It is really easy to get started with UI Testing in Xcode.
You add a new UI Testing target, like I have done here.
If you have used unit testing before,
you recognize getting a test case sub class
and the method created for you.
Had this been a unit test, you would now have
to write the test method using your bare hands.
Now we can write this for you recording the application. WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
Now we can write this for you recording the application.
Let's take a look.
I put my curser in the Test Method and start recording
by clicking the Record button at the bottom of the window.
While recording any event received
by my application will result
in source code being emitted into my Test Method.
For this test I want to configure a new game.
I'll go ahead, tap the Start a New Game button.
Note that as I tap the button, the corresponding line
of code showed up in the Source Editor right away.
Here I'm asked to pick a genre,
I'll go with sci-fi for this test.
Tap next. I'll invite a couple of players, Alice, Brandon,
I'll search for Stacy.
There she is.
I'll tap done. WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
I'll tap done.
Tap next. Finally tap the switch to mark the game as ready.
With this I'm done with -- with what I wanted to record here.
Let's take a look with what we ended up with.
This first line of code contains a query
to find a button label start a new game,
and it returns what we call an element, an element is a proxy
of the actual button in the application.
Using this element I can now access properties of the button
and also send events, in this case, a tap.
These next couple of lines contains the source code
for selecting the sci-fi genre and for tapping the Next button.
We designed the UI Testing APIs to be easy to read here,
as you see here, to be easy to write
and to help you produce robust tests.
Now for this to be a test it would have
to actually test something, and it already does. WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
If I were to run this test as-is,
it would implicitly validate that all the controls
that I interacted with while recording are still available
to me and fail a test if they're not.
In addition to this implicit validation,
I would typically also want
to explicitly validate other aspects of my application state
at different points throughout the test.
In this test, I selected a specific genre
and invited a specific set of players.
Let's add a couple of assertions to the test
to make sure that's what we ended up with.
These assertions validate that there are elements in the UI
of the last screen of the application
that contains the name of the genre
and names of these players.
With these assertions in place, I will be allowed
to run the test to make sure it performs as expected. WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
No hands.
The test passed.
[applause]
>> Joar Wingfors: This is a quick overview
of testing in Xcode 7.
I think you should all try it.
I think you'll love it.
More importantly, I think your customers will.
Back to you, Ken.
[applause]
>> Ken Orr: Great.
Thank you, Joar.
We have looked at just a few
of the many new features this morning.
I hope you're excited by what you've seen,
and you can see even more throughout this week WEBVTT X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
and you can see even more throughout this week
at the many great sessions which will go
into much more detail on Xcode 7.
If you haven't already, I encourage you
to download the new Xcode and let us know what you think.
Thank you very much.
[applause]