Full Code of jkyin/Subtitle for AI

master ca3472704888 cached
21 files
15.8 MB
836.4k tokens
1 requests
Download .txt
Showing preview only (3,926K chars total). Download the full file or copy to clipboard to get everything.
Repository: jkyin/Subtitle
Branch: master
Commit: ca3472704888
Files: 21
Total size: 15.8 MB

Directory structure:
gitextract_oegomsf2/

├── .gitignore
├── Hiragino Sans GB W3.otf
├── README.md
└── Subtitles/
    ├── 1. Class Logistics, Overview of iOS, MVC, Objective-C.ass
    ├── 10. Multithreading, Scroll View.ass
    ├── 11. Table View and iPad.ass
    ├── 12. Documents and Core Data.ass
    ├── 13. Core Data and Table View.ass
    ├── 14. UIApplication, Network Activity Indicator, and Maps.ass
    ├── 15. MapKit and Embed Segue.ass
    ├── 16. Modal Segues, Text Fields, Alerts, and Action Sheets.ass
    ├── 17. Camera, Core Motion, Application Lifecycle.ass
    ├── 18. Localization, Adding UI to Settings.ass
    ├── 2. Xcode 5.ass
    ├── 3. Objective-C.ass
    ├── 4. Foundation and Attributed Strings.ass
    ├── 5. View Controller Lifecycle.ass
    ├── 6. Polymorphism with Controllers, UINavigation, UITabBar.ass
    ├── 7. Views and Gestures.ass
    ├── 8. Protocols, Blocks, and Animation.ass
    └── 9. Animation and Autolayout.ass

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
.DS_Store

================================================
FILE: Hiragino Sans GB W3.otf
================================================
[File too large to display: 12.6 MB]

================================================
FILE: README.md
================================================
斯坦福大学公开课:iOS 7 应用开发
===============================

# 剧终

Demo
----

![](http://ww4.sinaimg.cn/large/69fe98c3gw1eelg25qchaj211y0lc0x1.jpg)

![](http://ww2.sinaimg.cn/large/69fe98c3gw1eelg2b8yesj211y0lctdi.jpg)

排版与格式
---------

* 字体为 Hiragino Sans GB W3。
* 中文字体大小为 20 号,英文字体大小为 12 号。
* Hiragino Sans GB W3.TTF 为「冬青黑体简体中文 W3」字体文件。

成品
----

成品已上传百度网盘,基本可以与网易同步  
链接: ~~http://pan.baidu.com/s/1bnF02Kn~~

如果你想要的是原版英文视频:  
请戳链接:链接: https://pan.baidu.com/s/1si5hs1qmpoS_dLu6HbUZGg 提取码: fdga 

说明
----

感谢 [@jannerchang](https://github.com/jannerchang) 提供的字幕。  
感谢 [@Bayonetta](https://github.com/Bayonetta) 提供原版视频共享。  
同步网易[斯坦福大学公开课:iOS 7 应用开发](http://v.163.com/special/opencourse/ios7.html)字幕文件。方便合成高清视频观看。




================================================
FILE: Subtitles/1. Class Logistics, Overview of iOS, MVC, Objective-C.ass
================================================
[Script Info]
; Script generated by Aegisub 3.1.2
; http://www.aegisub.org/
Title: Default Aegisub file
ScriptType: v4.00+
WrapStyle: 0
ScaledBorderAndShadow: yes
YCbCr Matrix: None
Last Style Storage: Default
Aegisub Scroll Position: 1114
Aegisub Active Line: 1120
Aegisub Video Zoom Percent: 1.000000

[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: yin,冬青黑体简体中文 W3,20,&H00FFFFFF,&HF0000000,&H00000000,&H32000000,0,0,0,0,100,100,0,0,1,1,0,2,5,5,5,134

[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:05.38,0:00:09.00,yin,,0,0,0,,斯坦福大学\N{\fs12}Stanford University.
Dialogue: 0,0:00:09.00,0:00:14.40,yin,,0,0,0,,好 欢迎来到 2013-14 学年斯坦福 CS193P 秋季课程\N{\fs12}Alright, so welcome to Stanford CS193p, fall of 2013-14 academic year.
Dialogue: 0,0:00:14.44,0:00:16.48,yin,,0,0,0,,这是我们的第一讲\N{\fs12}This is our very first lecture
Dialogue: 0,0:00:16.48,0:00:20.03,yin,,0,0,0,,我们要讲的是 iOS 应用开发\N{\fs12}and we are going to be covering developing applications for iOS,
Dialogue: 0,0:00:20.03,0:00:22.96,yin,,0,0,0,,这里将特别针对 iOS7\N{\fs12}so specifically iOS7.
Dialogue: 0,0:00:22.98,0:00:26.00,yin,,0,0,0,,今天的课分为上下两部分\N{\fs12}Today's lecture kind of has a first part and a second part.
Dialogue: 0,0:00:26.00,0:00:28.00,yin,,0,0,0,,前半部分是一些课务信息\N{\fs12}The first part is a little bit of logistics.
Dialogue: 0,0:00:28.00,0:00:30.99,yin,,0,0,0,,后半部分我将开始正式讲课\N{\fs12}The second part is I'm going to dive right into the course material
Dialogue: 0,0:00:30.99,0:00:33.00,yin,,0,0,0,,因为要讲的有很多\N{\fs12}because there's a lot to cover and so,
Dialogue: 0,0:00:33.00,0:00:36.00,yin,,0,0,0,,我需要尽早开始\N{\fs12}we need to start covering it.
Dialogue: 0,0:00:36.00,0:00:38.27,yin,,0,0,0,,这门课会学到一些什么呢\N{\fs12}So, what will I learn in this course?
Dialogue: 0,0:00:38.29,0:00:40.14,yin,,0,0,0,,你应该知道这门课会教些什么\N{\fs12}I think you know what you're going to learn in this course.
Dialogue: 0,0:00:40.14,0:00:42.57,yin,,0,0,0,,你们会学到如何创建很酷的 app\N{\fs12}You're going to learn how to build cool apps.
Dialogue: 0,0:00:42.59,0:00:45.70,yin,,0,0,0,,iOS 是一个很酷的 app 创建平台\N{\fs12}iOS is a really cool platform for building apps,
Dialogue: 0,0:00:45.72,0:00:47.00,yin,,0,0,0,,你们可能已经知道了\N{\fs12}you probably already know that.
Dialogue: 0,0:00:47.00,0:00:51.01,yin,,0,0,0,,app 非常酷 会有动画\N{\fs12}The apps look cool, they've got animation.
Dialogue: 0,0:00:51.01,0:00:53.35,yin,,0,0,0,,真正酷的是 它们就在你的口袋里\N{\fs12}What's really cool is they're in your pockets
Dialogue: 0,0:00:53.36,0:00:55.33,yin,,0,0,0,,你可以拿出来炫耀给朋友们\N{\fs12}so you can whip them out and show them to your friends.
Dialogue: 0,0:00:55.35,0:00:58.01,yin,,0,0,0,,你不需要发网址给他们 让他们去电脑上看\N{\fs12}You don't have to send them to a website or go get a computer.
Dialogue: 0,0:00:58.03,0:01:03.00,yin,,0,0,0,,而且你们将能在很短时间内轻松开发出强大的 app\N{\fs12}It's also really easy to develop really powerful apps in a really short amount of time,
Dialogue: 0,0:01:03.00,0:01:05.68,yin,,0,0,0,,这门课其实只有 10 周时间\N{\fs12}as you're going to find. This course is only 10 weeks long,
Dialogue: 0,0:01:05.70,0:01:08.00,yin,,0,0,0,,虽然这是斯坦福\N{\fs12}and while this is Stanford, I know,
Dialogue: 0,0:01:08.00,0:01:10.00,yin,,0,0,0,,你们都是很厉害的编程高手\N{\fs12}you're all really, really good programmers and all that,
Dialogue: 0,0:01:10.00,0:01:13.94,yin,,0,0,0,,但 10 周还是有点短 到最后\N{\fs12}it still, 10 weeks is not a lot of time, so when we get to the end,
Dialogue: 0,0:01:13.94,0:01:17.92,yin,,0,0,0,,你们会发现 这是一个很便于创建应用的平台\N{\fs12}you're going to see that it's a very leveraged platform for building things.
Dialogue: 0,0:01:17.94,0:01:20.62,yin,,0,0,0,,而且这个领域也非常活跃\N{\fs12}And, you know, the community is quite vibrant,
Dialogue: 0,0:01:20.64,0:01:23.51,yin,,0,0,0,,你可以通过 app 商店销售你的 app\N{\fs12}being able to distribute your apps via the app store
Dialogue: 0,0:01:23.53,0:01:26.70,yin,,0,0,0,,而不需要用盒子装起来在商店货架上出售\N{\fs12}and not have to put them in a box and put them on a shelf in a store,
Dialogue: 0,0:01:26.70,0:01:30.36,yin,,0,0,0,,这对于销售产品而言是一个巨大的不同\N{\fs12}is really a big, big difference when it comes to marketing a product.
Dialogue: 0,0:01:30.38,0:01:32.00,yin,,0,0,0,,你们会看到这个\N{\fs12}And you'll, you'll see that.
Dialogue: 0,0:01:32.00,0:01:36.51,yin,,0,0,0,,从这门课你们将学到的第二点是 现实世界应用\N{\fs12}The second thing you're going to learn in this course though is real-world application,
Dialogue: 0,0:01:36.53,0:01:40.22,yin,,0,0,0,,将其它课程中学到的很多计算机科学内容应用于现实\N{\fs12}a lot of the computer science things you're learning in other classes.
Dialogue: 0,0:01:40.73,0:01:42.50,yin,,0,0,0,,我们会用到网络\N{\fs12}So, we're going to be doing networking,
Dialogue: 0,0:01:42.50,0:01:44.50,yin,,0,0,0,,用到多线程\N{\fs12}we're going to do multithreaded,
Dialogue: 0,0:01:44.50,0:01:46.10,yin,,0,0,0,,用到各种图形\N{\fs12}we're going to be doing all kinds of graphics,
Dialogue: 0,0:01:46.10,0:01:47.50,yin,,0,0,0,,用到动画\N{\fs12}we're going to be doing animation,
Dialogue: 0,0:01:47.50,0:01:49.50,yin,,0,0,0,,用到面向对象的数据库\N{\fs12}we're going to do object-oriented databases,
Dialogue: 0,0:01:49.50,0:01:51.31,yin,,0,0,0,,这些东西都会被用于现实世界\N{\fs12}we're going to do all that stuff for real.
Dialogue: 0,0:01:51.31,0:01:55.50,yin,,0,0,0,,你们会了解到 如何应用所有这些计算机科学概念\N{\fs12}You're going to see what it looks like to apply all those computer science concepts,
Dialogue: 0,0:01:55.50,0:01:58.50,yin,,0,0,0,,特别是将它们结合到现实世界的舞台\N{\fs12}especially how to combine them into a real-world platform,
Dialogue: 0,0:01:58.50,0:02:00.50,yin,,0,0,0,,你制作的可是真正的 app\N{\fs12}where you're making real apps.
Dialogue: 0,0:02:00.50,0:02:04.96,yin,,0,0,0,,我原来的很多学生 成十上百\N{\fs12}And quite a few, many dozens of my former students have
Dialogue: 0,0:02:04.96,0:02:09.31,yin,,0,0,0,,都将他们的 app 发布到了 app 商店 你们应该也能做到\N{\fs12}shipped their apps on the app store and you may well too. So this is
Dialogue: 0,0:02:09.33,0:02:13.36,yin,,0,0,0,,这是一门很好的课程 让你们能够\N{\fs12}really, this is a good course to kind of combine or
Dialogue: 0,0:02:13.36,0:02:16.88,yin,,0,0,0,,将其它计算机科学课程上学到的很多知识\N{\fs12}synthesize all of the things you've learned in a lot of your other computer science classes
Dialogue: 0,0:02:16.88,0:02:20.68,yin,,0,0,0,,完美地结合到现实世界中\N{\fs12}and touch it up against the real world.
Dialogue: 0,0:02:20.68,0:02:24.44,yin,,0,0,0,,这门课的预备条件非常非常重要\N{\fs12}The prerequisites for this class are super duper important,
Dialogue: 0,0:02:24.44,0:02:27.77,yin,,0,0,0,,你们一定要确保满足这些预备条件\N{\fs12}This, it's just key to make sure you have these prerequisites
Dialogue: 0,0:02:27.77,0:02:31.50,yin,,0,0,0,,你们要想好 不满足这些条件的 不要选这门课\N{\fs12}and really think long and hard, if you don't, whether you want to give this class a go.
Dialogue: 0,0:02:31.50,0:02:36.99,yin,,0,0,0,,CS106 A 和 B 或 CS106X 肯定是需要的\N{\fs12}CS 106 A&B or, or CS106x are absolutely required.
Dialogue: 0,0:02:36.99,0:02:40.50,yin,,0,0,0,,如果没有相当的知识 想都不要想选这门课\N{\fs12}If you don't have that or equivalent, definitely, don't even think about it.
Dialogue: 0,0:02:40.50,0:02:44.12,yin,,0,0,0,,这学期我还基于经验加了第二个要求\N{\fs12}The second requirement I've added this quarter, based on experience,
Dialogue: 0,0:02:44.14,0:02:47.10,yin,,0,0,0,,也就是 CS107 或 CS108 更好\N{\fs12}is CS107 or CS108, which is great,
Dialogue: 0,0:02:47.10,0:02:50.50,yin,,0,0,0,,选修过 CS108 的同学 可以说为这门课做好了充分准备\N{\fs12}by the way, if you're taking CS108, you'll really be ready for this class.
Dialogue: 0,0:02:50.50,0:02:53.50,yin,,0,0,0,,或 CS110 就更好了\N{\fs12}Or even CS110, and part
Dialogue: 0,0:02:53.50,0:02:56.50,yin,,0,0,0,,我要求额外这些课程的原因在于\N{\fs12}of the reason I'm requiring these extra classes is just
Dialogue: 0,0:02:56.50,0:03:00.01,yin,,0,0,0,,希望你们有更多编程经验\N{\fs12}so you're farther along the programming experience curve
Dialogue: 0,0:03:00.03,0:03:02.25,yin,,0,0,0,,因为这门课中需要大量编程\N{\fs12}because this class is a lot of programming,
Dialogue: 0,0:03:02.25,0:03:06.50,yin,,0,0,0,,因此 习惯大量编程的同学 就能习惯这门课\N{\fs12}and so for those of you who are used to a lot of programming, you're used to it.
Dialogue: 0,0:03:06.50,0:03:10.50,yin,,0,0,0,,没有很多编程经验的同学会心想 喔 这里有很多编程\N{\fs12}But for those of you who aren't it's kind of like, whoa, do a lot of programming here.
Dialogue: 0,0:03:10.50,0:03:14.50,yin,,0,0,0,,这就有点让人心神不宁 所以我要求了这些条件\N{\fs12}It's going to be a little unbalancing. So, that's why I've required all those.
Dialogue: 0,0:03:14.50,0:03:16.50,yin,,0,0,0,,如果你做过暑期实习\N{\fs12}Now if you've done a summer internship
Dialogue: 0,0:03:16.50,0:03:18.50,yin,,0,0,0,,过程中做过一些编程\N{\fs12}of you've done some programming or something like that,
Dialogue: 0,0:03:18.50,0:03:23.50,yin,,0,0,0,,这显然也能替代 CS107 108 或 110 的作用\N{\fs12}that's definitely a substitute for CS107, 108, or 110, right?
Dialogue: 0,0:03:23.50,0:03:27.44,yin,,0,0,0,,或者如果你选修过更进阶的 CS 课程 当然也行\N{\fs12}Or if you've done some other CS class that's even more advanced than these, that's fine too.
Dialogue: 0,0:03:27.45,0:03:30.16,yin,,0,0,0,,你们需要了解这门课是一门\N{\fs12}You've just got to understand that this class is, you know,
Dialogue: 0,0:03:30.16,0:03:32.16,yin,,0,0,0,,编程课 有大量编程\N{\fs12}a programming class, there's a lot of programming.
Dialogue: 0,0:03:32.16,0:03:35.92,yin,,0,0,0,,最重要的是 你需要很熟悉面向对象编程\N{\fs12}And most importantly, you got to really be comfortable with object-oriented programming.
Dialogue: 0,0:03:35.94,0:03:38.05,yin,,0,0,0,,这里我列了一些术语\N{\fs12}So I put a bunch of terms up here,
Dialogue: 0,0:03:38.05,0:03:41.53,yin,,0,0,0,,如消息 实例变量 父类和子类\N{\fs12}like message and instance variable and superclass and subclass,
Dialogue: 0,0:03:41.53,0:03:44.50,yin,,0,0,0,,如果你不能像手心手背那样熟悉这些术语\N{\fs12}if you don't know these terms like the back of your hand,
Dialogue: 0,0:03:44.50,0:03:46.50,yin,,0,0,0,,要学好这门课将会很难\N{\fs12}it's going to be hard for you to get this class,
Dialogue: 0,0:03:46.50,0:03:48.79,yin,,0,0,0,,因为我会不断随口说出这些\N{\fs12}because I'm going to be throwing those terms out left, right, and center.
Dialogue: 0,0:03:48.81,0:03:51.50,yin,,0,0,0,,iOS7 完全是面向对象的\N{\fs12}iOS7 is completely object-oriented.
Dialogue: 0,0:03:51.50,0:03:54.50,yin,,0,0,0,,其整个结构 设计都是面向对象的\N{\fs12}Okay, the whole structure, the design of the thing, is object-oriented.
Dialogue: 0,0:03:54.50,0:03:57.50,yin,,0,0,0,,这是你必须知道的 如果你不知道\N{\fs12}So, you just got to know that, and if you don't know that,
Dialogue: 0,0:03:57.50,0:03:59.50,yin,,0,0,0,,你显然需要先学这些\N{\fs12}you definitely want to go get that first.
Dialogue: 0,0:03:59.50,0:04:02.50,yin,,0,0,0,,先去选 CS106A&B 或相当课程\N{\fs12}Okay? Take CS106a&b equivalent first,
Dialogue: 0,0:04:02.50,0:04:06.66,yin,,0,0,0,,然后再去增加一些编程经验才行\N{\fs12}and then get a little more programming experience and then you're good to go.
Dialogue: 0,0:04:06.68,0:04:10.27,yin,,0,0,0,,这门课需要大家编写 app\N{\fs12}We're going, you're going to be writing apps in this class
Dialogue: 0,0:04:10.27,0:04:15.50,yin,,0,0,0,,到第五周 第六周 你们需要写几十个类\N{\fs12}with dozens of classes that you're going to write by the fifth, sixth week so,
Dialogue: 0,0:04:15.50,0:04:19.86,yin,,0,0,0,,如果你原来写过的最大 app 只有 3 到 5 个类\N{\fs12}you know, if the biggest app you've ever written is got 3, or 4, or 5 classes in it,
Dialogue: 0,0:04:19.86,0:04:22.50,yin,,0,0,0,,这将是大幅的跨越\N{\fs12}oh, this is going to be a step up.
Dialogue: 0,0:04:23.95,0:04:28.50,yin,,0,0,0,,作业 前六七周是每周一次作业\N{\fs12}The assignments, we've got this weekly assignments for the first six or seven weeks,
Dialogue: 0,0:04:28.50,0:04:30.50,yin,,0,0,0,,最后是一个期末项目\N{\fs12}and then you've got a final project at the end.
Dialogue: 0,0:04:30.50,0:04:32.50,yin,,0,0,0,,所有作业都会详细给出 包括\N{\fs12}All of the homework assignments have detailed write-up
Dialogue: 0,0:04:32.50,0:04:36.01,yin,,0,0,0,,要求的任务是什么以及我们怎么评分\N{\fs12}of the required task and what we're evaluating you on.
Dialogue: 0,0:04:36.03,0:04:37.80,yin,,0,0,0,,而且我还会给出提示\N{\fs12}And they also have hints in there,
Dialogue: 0,0:04:37.81,0:04:40.50,yin,,0,0,0,,因为我不想把作业弄得奇难无比\N{\fs12}because I'm not trying to make the homework assignments be really, really hard,
Dialogue: 0,0:04:40.50,0:04:45.50,yin,,0,0,0,,而且所有作业基本上都是为了\N{\fs12}and all the homework assignments also directly are re --
Dialogue: 0,0:04:45.50,0:04:49.50,yin,,0,0,0,,巩固那一周课上所讲的知识\N{\fs12}they're basically reinforcing what has been taught in lecture in that week,
Dialogue: 0,0:04:49.50,0:04:52.18,yin,,0,0,0,,而不是一些随机布置的新学习任务\N{\fs12}they're not a bunch of random new stuff to learn.
Dialogue: 0,0:04:52.19,0:04:55.32,yin,,0,0,0,,我相信这种教学理念 也就是\N{\fs12}I'm a big believer in a teaching methodology, which is
Dialogue: 0,0:04:55.32,0:04:59.64,yin,,0,0,0,,首先我通过幻灯片给大家讲一个概念\N{\fs12}I'm going to tell you about a concept, via slides,
Dialogue: 0,0:04:59.64,0:05:02.50,yin,,0,0,0,,然后我再给大家演示例子\N{\fs12}and then I'm going to show you it by demoing it to you,
Dialogue: 0,0:05:02.50,0:05:04.50,yin,,0,0,0,,实际写一个用到此概念的应用\N{\fs12}actually writing an application that does it, then I'm going
Dialogue: 0,0:05:04.50,0:05:06.50,yin,,0,0,0,,然后再让你们在作业中做这个\N{\fs12}to ask you to do it on the homework.
Dialogue: 0,0:05:06.50,0:05:10.50,yin,,0,0,0,,课上的每一点内容我都会这么来讲\N{\fs12}So that's three times you're going to see every single thing pretty much in this class.
Dialogue: 0,0:05:10.50,0:05:13.08,yin,,0,0,0,,到最后 你们就知道怎么做了\N{\fs12}By the end of that, you're going to know how to do it.
Dialogue: 0,0:05:13.10,0:05:15.50,yin,,0,0,0,,你们就会很有信心 很有经验了\N{\fs12}Okay? And you're going to feel confident and experienced to do it.
Dialogue: 0,0:05:15.50,0:05:17.50,yin,,0,0,0,,作业都是这样的\N{\fs12}So the homework is all about that.
Dialogue: 0,0:05:17.50,0:05:22.50,yin,,0,0,0,,都是课堂上我讲过的 让你们去应用\N{\fs12}It's about just doing what you saw me do in class and talk about in class and apply it.
Dialogue: 0,0:05:22.50,0:05:27.25,yin,,0,0,0,,好 下面我将简要讲一下 iOS 中有些什么\N{\fs12}Alright. Now I'm going to really briefly go over what's in iOS,
Dialogue: 0,0:05:27.25,0:05:29.30,yin,,0,0,0,,我想你们大多数人知道 iOS 中有什么\N{\fs12}I think most of you know what's in iOS, hopefully
Dialogue: 0,0:05:29.30,0:05:31.77,yin,,0,0,0,,你们都见过 iOS 设备\N{\fs12}you've all seen an iOS device
Dialogue: 0,0:05:31.77,0:05:35.50,yin,,0,0,0,,我打赌 在座 90% 的人应该口袋里都有一个\N{\fs12}or you have one in your pocket, I bet 90 percent of you do in this room,
Dialogue: 0,0:05:35.50,0:05:38.50,yin,,0,0,0,,不过我准备总结一下\N{\fs12}but I'm going to try and summarize it,
Dialogue: 0,0:05:38.50,0:05:40.50,yin,,0,0,0,,这有些难\N{\fs12}this is really hard to do because I'm going to try
Dialogue: 0,0:05:40.50,0:05:43.50,yin,,0,0,0,,因为我要用四五分钟或更少时间来讲\N{\fs12}and do it in four minutes or less, or five minutes,
Dialogue: 0,0:05:43.50,0:05:46.27,yin,,0,0,0,,这里内容其实很多 真要讲清楚可能需要两节课时间\N{\fs12}and it's so big that, I mean, I could have two lectures
Dialogue: 0,0:05:46.27,0:05:49.19,yin,,0,0,0,,这里内容其实很多 真要讲清楚可能需要两节课时间\N{\fs12}where I just talk about all the different things and just summarize them.
Dialogue: 0,0:05:49.21,0:05:54.62,yin,,0,0,0,,这里我只是把事物组织成一些有意义的组\N{\fs12}So, this is going to try and group them into some sort of sensible groups
Dialogue: 0,0:05:54.62,0:05:58.38,yin,,0,0,0,,让你们理解从开发视角应该怎么看它们\N{\fs12}so you have an idea of what's there from a development standpoint,
Dialogue: 0,0:05:58.38,0:06:02.19,yin,,0,0,0,,然后我们就会开始做这些 你会开始意识到 哦\N{\fs12}then when we go off and start doing it all then you'll start realizing whoa,
Dialogue: 0,0:06:02.21,0:06:04.50,yin,,0,0,0,,你会开始学习如何查说明文档 你会意识到 哦\N{\fs12}and once you learn how to look in the documentation you'll see, oh,
Dialogue: 0,0:06:04.50,0:06:06.50,yin,,0,0,0,,查查这些 你就能知道怎么做\N{\fs12}look at all that stuff in there, and you'll figure it out.
Dialogue: 0,0:06:06.50,0:06:08.23,yin,,0,0,0,,这只是高层级的概览\N{\fs12}So this is just a high-level overview.
Dialogue: 0,0:06:08.25,0:06:13.50,yin,,0,0,0,,我将这些分为四组\N{\fs12}So, I've used this division into these four, kind of groups.
Dialogue: 0,0:06:13.50,0:06:17.19,yin,,0,0,0,,一是核心操作系统层 这是很接近硬件的一层\N{\fs12}Core OS, which is the stuff that's close to the hardware.
Dialogue: 0,0:06:17.19,0:06:20.50,yin,,0,0,0,,核心服务层 这是之上的面向对象的一层\N{\fs12}Core services, which is an object-oriented on top of that,
Dialogue: 0,0:06:20.50,0:06:24.01,yin,,0,0,0,,这让你总能在面向对象的层上进行编程\N{\fs12}that kind of makes it so you always are programming an object-oriented layer.
Dialogue: 0,0:06:24.01,0:06:27.75,yin,,0,0,0,,媒体层 因为这些设备基本上是 iPod\N{\fs12}Media, because these devices are basically iPods
Dialogue: 0,0:06:27.75,0:06:29.93,yin,,0,0,0,,带一个手机或者大屏幕\N{\fs12}with a phone in them or with a big screen on them,
Dialogue: 0,0:06:29.95,0:06:32.50,yin,,0,0,0,,媒体在这些设备上很重要\N{\fs12}but media is really important to these devices,
Dialogue: 0,0:06:32.50,0:06:35.01,yin,,0,0,0,,最后是触控应用层 这是 UI 层\N{\fs12}and then finally Cocoa Touch, which is the UI layer.
Dialogue: 0,0:06:35.03,0:06:37.50,yin,,0,0,0,,包括按钮和开关这些\N{\fs12}Of buttons and all the switches, things like that.
Dialogue: 0,0:06:37.50,0:06:40.50,yin,,0,0,0,,我们来谈谈这些层中都有什么\N{\fs12}So let's talk about what's in each of those layers, kind of,
Dialogue: 0,0:06:40.50,0:06:43.50,yin,,0,0,0,,浅析一下这些层\N{\fs12}little skimming the surface of what's in those layers.
Dialogue: 0,0:06:43.50,0:06:48.50,yin,,0,0,0,,在接近硬件的核心操作系统层 是一个 Unix 内核\N{\fs12}At the Core OS layer, near the hardware, is a Unix kernel.
Dialogue: 0,0:06:48.50,0:06:52.50,yin,,0,0,0,,这个设备上是 Unix 操作系统\N{\fs12}Okay? This is a Unix operating system on this device.
Dialogue: 0,0:06:52.50,0:06:55.86,yin,,0,0,0,,基于 BSD 的 Unix 版本\N{\fs12}And BSD-based mock,
Dialogue: 0,0:06:55.86,0:06:58.50,yin,,0,0,0,,Unix 有的一切它都有\N{\fs12}and so you get everything you get with Unix.
Dialogue: 0,0:06:58.50,0:07:01.50,yin,,0,0,0,,它有套接字 有文件系统\N{\fs12}You're getting sockets and you're getting file system,
Dialogue: 0,0:07:01.50,0:07:03.78,yin,,0,0,0,,权限 所有这些\N{\fs12}permissions, all that stuff,
Dialogue: 0,0:07:03.78,0:07:07.50,yin,,0,0,0,,另外 这里还有一些特别用于移动设备的东西\N{\fs12}plus you're getting a bunch of other stuff that's kind of specific to a mobile
Dialogue: 0,0:07:07.50,0:07:09.77,yin,,0,0,0,,例如电源管理\N{\fs12}device like this, like power management,
Dialogue: 0,0:07:09.77,0:07:14.50,yin,,0,0,0,,用于安全管理的钥匙串访问\N{\fs12}and key chain access to kind of manage the security of things.
Dialogue: 0,0:07:14.50,0:07:16.50,yin,,0,0,0,,Bonjour 这是这种网络\N{\fs12}Bonjour, which is this kind of network,
Dialogue: 0,0:07:16.50,0:07:18.50,yin,,0,0,0,,在网络上找其它东西\N{\fs12}finding other things on the network.
Dialogue: 0,0:07:18.50,0:07:23.04,yin,,0,0,0,,所有这些都有 下方是这个很强大的操作系统\N{\fs12}So it's got all that stuff, it's a very powerful underlying operating system.
Dialogue: 0,0:07:23.04,0:07:26.50,yin,,0,0,0,,但大多数 API 都是用 C 写的\N{\fs12}But all of that API or most of it is in C,
Dialogue: 0,0:07:26.50,0:07:29.50,yin,,0,0,0,,我们会完全在面向对象层进行编程\N{\fs12}and we want to be programming kind of purely object-oriented layer.
Dialogue: 0,0:07:29.50,0:07:32.50,yin,,0,0,0,,我们主要需要触及到的\N{\fs12}So we're going to be mostly operating when we're talking,
Dialogue: 0,0:07:32.50,0:07:35.50,yin,,0,0,0,,是核心服务层的这些东西\N{\fs12}touching those things at the Core Services layer.
Dialogue: 0,0:07:35.50,0:07:39.50,yin,,0,0,0,,这一层有让语言更加强劲的东西\N{\fs12}So this layer has things like language, things that,
Dialogue: 0,0:07:39.50,0:07:41.28,yin,,0,0,0,,这一层有让语言更加强劲的东西\N{\fs12}that kind of make the language more powerful,
Dialogue: 0,0:07:41.28,0:07:45.50,yin,,0,0,0,,例如数组 字典 字符串等等\N{\fs12}like arrays and dictionaries, and strings and things like that,
Dialogue: 0,0:07:45.50,0:07:49.08,yin,,0,0,0,,而且它还有面向对象的方式来访问文件系统\N{\fs12}plus it has object-oriented ways to access the file system,
Dialogue: 0,0:07:49.10,0:07:51.50,yin,,0,0,0,,例如 它有面向对象的方式\N{\fs12}it has object-oriented ways to find out the GPS
Dialogue: 0,0:07:51.50,0:07:53.99,yin,,0,0,0,,来寻找设备的 GPS 位置\N{\fs12}location of your device, for example.
Dialogue: 0,0:07:54.01,0:07:57.50,yin,,0,0,0,,它还有方式来进行多线程操作\N{\fs12}It has ways to do multithreading.
Dialogue: 0,0:07:57.50,0:08:00.45,yin,,0,0,0,,所有这些你想要能够做到的事情\N{\fs12}All this stuff what you want to be able to do,
Dialogue: 0,0:08:00.45,0:08:04.93,yin,,0,0,0,,不过所有这些你都希望以面向对象的方式来思考\N{\fs12}but you want to stay in an object-oriented kind of mindset as you're doing them all.
Dialogue: 0,0:08:04.95,0:08:09.97,yin,,0,0,0,,核心服务层有一个巨大的基础层用于做这些\N{\fs12}There's a huge layer, foundational layer there at Core services for doing that.
Dialogue: 0,0:08:09.97,0:08:12.99,yin,,0,0,0,,再看媒体层 不要小看这一层\N{\fs12}At the media layer, don't sleep on this layer,
Dialogue: 0,0:08:12.99,0:08:16.00,yin,,0,0,0,,这一层很重要 这里有视频 有视频编辑\N{\fs12}really important layer, you've got video here, you've got video editing,
Dialogue: 0,0:08:16.01,0:08:18.28,yin,,0,0,0,,当然 这里有能够显示的图像\N{\fs12}you got images, of course, that it can display,
Dialogue: 0,0:08:18.28,0:08:21.19,yin,,0,0,0,,有很强大音频 用于 3D 音效\N{\fs12}it's incredibly powerful audio for doing 3D audio,
Dialogue: 0,0:08:21.19,0:08:23.50,yin,,0,0,0,,例如游戏中 可以有泰拳打击的感觉\N{\fs12}if you have games, you can make the Thai fighters feel
Dialogue: 0,0:08:23.50,0:08:25.50,yin,,0,0,0,,就像真实的打斗一样\N{\fs12}like they're ripping by you and stuff.
Dialogue: 0,0:08:25.50,0:08:27.26,yin,,0,0,0,,所有这些都在这里\N{\fs12}All that stuff is in here.
Dialogue: 0,0:08:27.26,0:08:29.50,yin,,0,0,0,,iOS 的这部分\N{\fs12}This is part of, the part of iOS
Dialogue: 0,0:08:29.50,0:08:31.82,yin,,0,0,0,,我无法很深入讲解\N{\fs12}that really I can't cover in a lot of depth.
Dialogue: 0,0:08:31.84,0:08:35.15,yin,,0,0,0,,我只是想让你们知道有这么一层\N{\fs12}I'm just going to try and let you know that it's there and you're going to dive down
Dialogue: 0,0:08:35.15,0:08:39.50,yin,,0,0,0,,你们可以根据未来应用程序需求来使用它\N{\fs12}depending on what kind of applications, later in your life, you want to build.
Dialogue: 0,0:08:39.50,0:08:44.50,yin,,0,0,0,,不过这方面量很大 苹果设备根本上显然是多媒体设备\N{\fs12}But there's an enormous amount there. This is a fundamentally, a multimedia device, obviously,
Dialogue: 0,0:08:44.50,0:08:48.50,yin,,0,0,0,,最后是触控应用层 我们大多数时间都会花在这里\N{\fs12}and then, Cocoa Touch is where we're going to spend most of our time.
Dialogue: 0,0:08:48.50,0:08:53.69,yin,,0,0,0,,这里你会设计一些按钮 滑动条 文本框\N{\fs12}This is where you are going to be building buttons and sliders and text fields,
Dialogue: 0,0:08:53.69,0:08:57.58,yin,,0,0,0,,这里有交互 动画发生 事物滑进滑出\N{\fs12}talking to each other, and animation happening, things sliding in and out, and,
Dialogue: 0,0:08:57.58,0:09:00.50,yin,,0,0,0,,淡出淡入等等\N{\fs12}you know, fading out and fading in.
Dialogue: 0,0:09:00.50,0:09:04.88,yin,,0,0,0,,如果你要使用用户相机中的照片 你可以这样做\N{\fs12}If you want to get the, a picture from the camera from the user, you can do that.
Dialogue: 0,0:09:04.89,0:09:06.52,yin,,0,0,0,,还有本地化\N{\fs12}Things like localization
Dialogue: 0,0:09:06.52,0:09:08.89,yin,,0,0,0,,让你的 app 能够在世界上很多国家运行\N{\fs12}so that you're app can run in many countries in the world
Dialogue: 0,0:09:08.89,0:09:10.89,yin,,0,0,0,,由此来提高销量\N{\fs12}and up your sales by doing that.
Dialogue: 0,0:09:10.91,0:09:15.50,yin,,0,0,0,,还有一整套地图包 包括你们在 iOS7 中见过的 3D 地图\N{\fs12}A whole map kit for doing all the 3D maps that you've probably seen in iOS7 and all
Dialogue: 0,0:09:15.50,0:09:17.50,yin,,0,0,0,,所有这些都在这里\N{\fs12}that stuff is all in there.
Dialogue: 0,0:09:18.58,0:09:23.50,yin,,0,0,0,,视图中还可以将一整个网页浏览器放到一个小矩形中\N{\fs12}And, there's even a view in there that's an entire web browser in a little rectangle
Dialogue: 0,0:09:23.50,0:09:25.50,yin,,0,0,0,,让它显示在你的 app 中\N{\fs12}that you can just plop right into your app.
Dialogue: 0,0:09:25.50,0:09:28.74,yin,,0,0,0,,这些是高层级的对象\N{\fs12}So these are really high-level objects,
Dialogue: 0,0:09:28.75,0:09:31.80,yin,,0,0,0,,我们会深入探讨这一层\N{\fs12}and we're going to really be diving into this layer, alright?
Dialogue: 0,0:09:31.80,0:09:33.50,yin,,0,0,0,,这是最重要的内容\N{\fs12}So this is really the primary.
Dialogue: 0,0:09:33.50,0:09:36.78,yin,,0,0,0,,这里触控叫作 Cocoa Touch 是因为\N{\fs12}And it's called Cocoa Touch because
Dialogue: 0,0:09:36.78,0:09:40.50,yin,,0,0,0,,这里的 API 最初是为 Mac OS X 开发的\N{\fs12}the API in here was originally developed for Mac OS X,
Dialogue: 0,0:09:40.50,0:09:42.36,yin,,0,0,0,,它叫 Cocoa\N{\fs12}and it was called Cocoa,
Dialogue: 0,0:09:42.36,0:09:45.45,yin,,0,0,0,,之后当它们被适用于 iOS\N{\fs12}and of course then when they went to iOS, they adapted,
Dialogue: 0,0:09:45.45,0:09:48.50,yin,,0,0,0,,很多 API 都能在两平台之间共享\N{\fs12}and a lot of API is shared between the two platforms, and, in fact,
Dialogue: 0,0:09:48.50,0:09:51.50,yin,,0,0,0,,如果你开发了一个 iOS app 然后某天你想 哦\N{\fs12}if you develop an iOS app and then you say someday, oh,
Dialogue: 0,0:09:51.50,0:09:54.99,yin,,0,0,0,,我要为 Mac 开发一个 app 使用 Cocoa 这会非常类似\N{\fs12}I want to develop an app for the Mac using Cocoa, it's going to be very similar.
Dialogue: 0,0:09:55.00,0:09:58.50,yin,,0,0,0,,你会感觉非常熟悉\N{\fs12}Okay? You're going to be really, it's going to look familiar.
Dialogue: 0,0:09:58.50,0:10:03.50,yin,,0,0,0,,Cocoa Touch 显然是 Cocoa 的触控版本\N{\fs12}So Cocoa Touch, obviously, is the touchscreen version of that, of Cocoa.
Dialogue: 0,0:10:04.34,0:10:08.50,yin,,0,0,0,,Cocoa 这个技术已经存在很久了\N{\fs12}This technology, Cocoa, has been around a long time.
Dialogue: 0,0:10:08.50,0:10:11.50,yin,,0,0,0,,也许三十年了 难以置信吧\N{\fs12}Probably almost 30 years, believe it or not.
Dialogue: 0,0:10:11.50,0:10:15.97,yin,,0,0,0,,甚至在苹果开始使用 Mac OS 之前\N{\fs12}From even before Apple acquired it to make Mac OS,
Dialogue: 0,0:10:15.97,0:10:19.89,yin,,0,0,0,,现在是 Mac OS X 这是一种很成熟的API\N{\fs12}what is now Mac OS X, and so it's a very mature API.
Dialogue: 0,0:10:19.91,0:10:25.35,yin,,0,0,0,,它是经过深思熟虑的 如果你能顺着它来\N{\fs12}And it's very well thought out, so, especially if you go with the flow of it,
Dialogue: 0,0:10:25.36,0:10:28.50,yin,,0,0,0,,你会发现创建强大的程序是很容易的\N{\fs12}it's very easy to build really powerful things.
Dialogue: 0,0:10:28.50,0:10:30.50,yin,,0,0,0,,这就是这其中的内容\N{\fs12}So, that's what's in there.
Dialogue: 0,0:10:30.50,0:10:33.35,yin,,0,0,0,,下面再来看作为程序员 作为开发者\N{\fs12}So let's talk about the tools we use as programmers,
Dialogue: 0,0:10:33.36,0:10:36.19,yin,,0,0,0,,我们需要什么工具来创建 app\N{\fs12}as developers, to build these apps.
Dialogue: 0,0:10:36.19,0:10:38.50,yin,,0,0,0,,我把这些分成了四段\N{\fs12}And I've divided those into kind of four sections here.
Dialogue: 0,0:10:38.50,0:10:42.50,yin,,0,0,0,,一是实际编程用的工具\N{\fs12}One is the tools, the actual programming tools,
Dialogue: 0,0:10:42.50,0:10:47.86,yin,,0,0,0,,这个平台很好的地方在于 它是一个工具满足所有用途\N{\fs12}and what's great, on this platform, is it's pretty much a one-tool fits all.
Dialogue: 0,0:10:47.87,0:10:49.98,yin,,0,0,0,,只有一个工具 XCode 5\N{\fs12}Okay? There's this one tool, XCode 5,
Dialogue: 0,0:10:50.00,0:10:51.50,yin,,0,0,0,,一切都在这里面\N{\fs12}and everything's in there.
Dialogue: 0,0:10:51.50,0:10:53.50,yin,,0,0,0,,调试器在这里 源代码编辑\N{\fs12}Your debugger's in there, all your source code editing,
Dialogue: 0,0:10:53.50,0:10:57.85,yin,,0,0,0,,源代码控制 UI 构建 一切都在这个工具里\N{\fs12}your source code control, the UI building, everything is in this one app.
Dialogue: 0,0:10:57.87,0:11:00.50,yin,,0,0,0,,然后还有一个辅助的 Instruments\N{\fs12}There's a little adjunct there, instruments, which is for things
Dialogue: 0,0:11:00.50,0:11:05.50,yin,,0,0,0,,用于 app 代码分析 内存管理等等\N{\fs12}like profiling your app and things like that. Memory usage, those kind of things,
Dialogue: 0,0:11:05.50,0:11:08.61,yin,,0,0,0,,不过这些都包含在 XCode 5 中\N{\fs12}but you're really, all was inside XCode 5,
Dialogue: 0,0:11:08.61,0:11:10.50,yin,,0,0,0,,这很棒 因为 要知道\N{\fs12}which is really nice because, you know,
Dialogue: 0,0:11:10.50,0:11:13.39,yin,,0,0,0,,调试时 你一般是在同时编辑代码\N{\fs12}when you're debugging, you're usually editing your code at the same time,
Dialogue: 0,0:11:13.39,0:11:14.50,yin,,0,0,0,,来来回回\N{\fs12}back and forth, back and forth,
Dialogue: 0,0:11:14.50,0:11:17.26,yin,,0,0,0,,如果要在不同程序中来回切换 就会很烦人\N{\fs12}you're going to different apps and all that would be a pain in the neck,
Dialogue: 0,0:11:17.26,0:11:20.63,yin,,0,0,0,,这个工具对屏幕空间的分配也做得很好\N{\fs12}and they've really done a good job of arranging the screen space
Dialogue: 0,0:11:20.63,0:11:23.84,yin,,0,0,0,,所有不同任务很好地被分配到不同屏幕空间中\N{\fs12}so that it's sharing between all these different tasks that you need to do.
Dialogue: 0,0:11:23.85,0:11:25.98,yin,,0,0,0,,这是首要工具 XCode 5\N{\fs12}So that's the primary tool, XCode 5,
Dialogue: 0,0:11:25.98,0:11:30.50,yin,,0,0,0,,这堂课后 你们都应该到 Mac App 商店\N{\fs12}you should all, right after this class if you want, go to the Mac App store,
Dialogue: 0,0:11:30.50,0:11:34.04,yin,,0,0,0,,不是 iOS 设备商店 而是 Mac 上的 Mac App 商店\N{\fs12}not the store on you iOS device, the Mac App Store on your Mac,
Dialogue: 0,0:11:34.04,0:11:38.15,yin,,0,0,0,,下载这个 它是免费的 上周五刚出\N{\fs12}and download this. It's free, available, came out last Friday,
Dialogue: 0,0:11:38.15,0:11:42.02,yin,,0,0,0,,你们可以下载安装 然后开始倒弄\N{\fs12}and you can download it, install it, and, you know, start playing around with it.
Dialogue: 0,0:11:42.04,0:11:45.17,yin,,0,0,0,,有些人可能在 CS106 这样的课上用过 XCode\N{\fs12}Some of you might have already used XCode, like in CS106,
Dialogue: 0,0:11:45.19,0:11:47.50,yin,,0,0,0,,多少人用过 XCode 举手我看看\N{\fs12}raise your hand if you've used XCode before for anything.
Dialogue: 0,0:11:47.50,0:11:50.50,yin,,0,0,0,,好 2/3 或更多 大约 3/4 的人用过\N{\fs12}Okay, so two-thirds or more, three-quarters of you.
Dialogue: 0,0:11:50.50,0:11:53.50,yin,,0,0,0,,你们会很习惯它 你们将会把 XCode\N{\fs12}So, you're going to be used it. You're just going to start using XCode now
Dialogue: 0,0:11:53.50,0:11:55.50,yin,,0,0,0,,用于 iOS 应用\N{\fs12}to develop for iOS, alright?
Dialogue: 0,0:11:55.50,0:11:58.50,yin,,0,0,0,,有一个新语言需要你们学 Objective-C\N{\fs12}There's a new language for you to learn, objective C,
Dialogue: 0,0:11:58.50,0:12:00.50,yin,,0,0,0,,这个语言样子有点滑稽\N{\fs12}it's kind of a funny-looking language, okay,
Dialogue: 0,0:12:00.50,0:12:04.50,yin,,0,0,0,,它使用方括号和冒号 消息调用没有圆括号\N{\fs12}it's got square brackets and colons, no parentheses on message calls,
Dialogue: 0,0:12:04.50,0:12:08.96,yin,,0,0,0,,熟悉 Jave 或 C++ 的人会觉得这有些奇怪\N{\fs12}which is kind of weird for people who are coming from Java or C++ or whatever.
Dialogue: 0,0:12:08.96,0:12:11.50,yin,,0,0,0,,参数不是放在圆括号里\N{\fs12}The arguments are not put in parentheses or whatever,
Dialogue: 0,0:12:11.50,0:12:13.50,yin,,0,0,0,,我将详细讲解 Objective-C\N{\fs12}and I'm going to show you all about objective C,
Dialogue: 0,0:12:13.50,0:12:16.08,yin,,0,0,0,,我不指望你们对它有任何了解\N{\fs12}I don't expect you to know anything about it coming in,
Dialogue: 0,0:12:16.09,0:12:19.96,yin,,0,0,0,,你们应该都很熟悉 Java 和 C++ 这是 CS106A 和 B 的内容\N{\fs12}and if you know Java and C++, which you should if you've taken CS106A&B,
Dialogue: 0,0:12:19.96,0:12:23.39,yin,,0,0,0,,那么 Objective-C 将不会有太大难度\N{\fs12}then objective C is not going to be a big leap for you.
Dialogue: 0,0:12:23.39,0:12:24.72,yin,,0,0,0,,它有一点不同\N{\fs12}It's a little bit different language,
Dialogue: 0,0:12:24.72,0:12:27.50,yin,,0,0,0,,例如 它比 Java 更快更宽松\N{\fs12}it's a little more fast and loose than Java, for example,
Dialogue: 0,0:12:27.50,0:12:30.89,yin,,0,0,0,,比 C++ 更简单 更优美\N{\fs12}and it's a little more, kind of simple and elegant, than C++,
Dialogue: 0,0:12:30.91,0:12:32.63,yin,,0,0,0,,当涉及到面向对象的东西时\N{\fs12}when it comes to the object-oriented stuff. So,
Dialogue: 0,0:12:32.63,0:12:34.72,yin,,0,0,0,,我想 你们会喜欢它的\N{\fs12}I think you'll like it.
Dialogue: 0,0:12:34.74,0:12:39.09,yin,,0,0,0,,有些人可能很喜欢正确编程这类概念\N{\fs12}Some of you who are very, you know, correct programming kind of thing,
Dialogue: 0,0:12:39.09,0:12:42.28,yin,,0,0,0,,喜欢 Java 觉得 Objective-C 太过宽松\N{\fs12}you love Java, might find objective C a little wild west for you,
Dialogue: 0,0:12:42.28,0:12:44.50,yin,,0,0,0,,不过 你应该能够克服\N{\fs12}but you'll get over it.
Dialogue: 0,0:12:44.50,0:12:45.74,yin,,0,0,0,,框架\N{\fs12}Frameworks,
Dialogue: 0,0:12:45.74,0:12:50.50,yin,,0,0,0,,显然 任何像这样的大系统一般都会将对象组到库中\N{\fs12}obviously, any big system like this groups all of its objects into libraries, essentially.
Dialogue: 0,0:12:50.50,0:12:53.17,yin,,0,0,0,,iOS 中我们称之为框架\N{\fs12}We call them Frameworks in iOS,
Dialogue: 0,0:12:53.19,0:12:56.50,yin,,0,0,0,,iOS 中有数十个这样的框架\N{\fs12}so there are dozens of frameworks in iOS.
Dialogue: 0,0:12:56.50,0:12:59.24,yin,,0,0,0,,课程最开始我们要讲两个主要框架\N{\fs12}The two main ones we're going to look at, at the beginning of the course, are
Dialogue: 0,0:12:59.24,0:13:02.44,yin,,0,0,0,,一是 Foundation 框架 所有核心服务都在这里\N{\fs12}foundation, that's where all that core services stuff is,
Dialogue: 0,0:13:02.45,0:13:04.50,yin,,0,0,0,,例如数字和字典 所有这些\N{\fs12}like arrays and dictionaries and all that.
Dialogue: 0,0:13:04.50,0:13:05.74,yin,,0,0,0,,然后是UIKit\N{\fs12}And then UI kit, okay,
Dialogue: 0,0:13:05.74,0:13:08.06,yin,,0,0,0,,按钮 滑动条这些东西就在这里\N{\fs12}that's where buttons and sliders and all those things are,
Dialogue: 0,0:13:08.06,0:13:10.50,yin,,0,0,0,,这是两个主要框架 不过还有很多 例如\N{\fs12}so those are the two main ones, but, there's a whole bunch of other ones, like,
Dialogue: 0,0:13:10.50,0:13:12.50,yin,,0,0,0,,看到这里写的 Core Data 了吗\N{\fs12}you see the Core Data written up there,
Dialogue: 0,0:13:12.50,0:13:14.50,yin,,0,0,0,,这是面向对象的数据库\N{\fs12}that's the object-oriented database.
Dialogue: 0,0:13:14.50,0:13:16.50,yin,,0,0,0,,我们会谈到这个\N{\fs12}Okay? So we're going to be doing that.
Dialogue: 0,0:13:16.50,0:13:19.50,yin,,0,0,0,,Core Motion 这是陀螺仪和加速计\N{\fs12}Core Motion, that's the gyro and accelerometer.
Dialogue: 0,0:13:19.50,0:13:21.50,yin,,0,0,0,,Map Kit 显然是地图\N{\fs12}Map Kit, obviously the maps.
Dialogue: 0,0:13:21.50,0:13:23.50,yin,,0,0,0,,还有很多其它的\N{\fs12}And there's dozens more.
Dialogue: 0,0:13:23.50,0:13:25.50,yin,,0,0,0,,我们会尽可能多地讲到这些\N{\fs12}And we'll cover as many of them as we can,
Dialogue: 0,0:13:25.50,0:13:28.50,yin,,0,0,0,,显然我们只有 10 周 但我会尽可能地多讲\N{\fs12}obviously we can't do it all in 10 weeks, but we'll do as much as we can.
Dialogue: 0,0:13:28.50,0:13:31.93,yin,,0,0,0,,该平台中开发应用的最后一部分\N{\fs12}And then the last part of developing application in this platform
Dialogue: 0,0:13:31.93,0:13:34.50,yin,,0,0,0,,是一种叫作 MVC 的设计策略\N{\fs12}is a design strategy called MVC.
Dialogue: 0,0:13:35.11,0:13:38.89,yin,,0,0,0,,这并非 iOS 所独有的 其它平台也有使用 MVC\N{\fs12}Now, this is not unique to iOS, other platforms use MVC,
Dialogue: 0,0:13:38.91,0:13:40.37,yin,,0,0,0,,模型 视图 控制器\N{\fs12}Model View Controller,
Dialogue: 0,0:13:40.37,0:13:42.50,yin,,0,0,0,,作为基本设计策略\N{\fs12}as their fundamental design strategy.
Dialogue: 0,0:13:42.50,0:13:46.50,yin,,0,0,0,,在座有多少人曾使用过 MVC\N{\fs12}So how many people in this room have used MVC on any platform?
Dialogue: 0,0:13:46.50,0:13:48.85,yin,,0,0,0,,大约有一半 你们知道这是什么\N{\fs12}Okay, so about half, so you'll know what this is.
Dialogue: 0,0:13:48.87,0:13:52.07,yin,,0,0,0,,我会为不了解的同学简单讲一遍 MVC\N{\fs12}So, I'm actually going to go over MVC for those of you who haven't
Dialogue: 0,0:13:52.07,0:13:53.50,yin,,0,0,0,,我会讲得很快\N{\fs12}and I'll go through it pretty quickly, because
Dialogue: 0,0:13:53.50,0:13:56.72,yin,,0,0,0,,因为有一半的人都用过它\N{\fs12}it looks like most of you, half of you have done it,
Dialogue: 0,0:13:56.72,0:14:01.50,yin,,0,0,0,,对于已经知道 MVC 是什么的人 这里我讲 MVC\N{\fs12}and the main thing to see in MVC here, for those of you who already know what it is,
Dialogue: 0,0:14:01.50,0:14:03.96,yin,,0,0,0,,是为了让你们了解我怎么讲到这些\N{\fs12}is to see how I talk about it
Dialogue: 0,0:14:03.96,0:14:06.50,yin,,0,0,0,,从而当我在 iOS 语境下讲到它时\N{\fs12}so that when we get into iOS
Dialogue: 0,0:14:06.50,0:14:10.11,yin,,0,0,0,,比如我讲你的模型是独立于 UI 的\N{\fs12}and I start saying things like your model is UI independent,
Dialogue: 0,0:14:10.11,0:14:13.50,yin,,0,0,0,,你们知道我在讲什么\N{\fs12}you'll know what I'm talking about and we'll all be on the same page.
Dialogue: 0,0:14:13.50,0:14:18.50,yin,,0,0,0,,这里是为了让我们所有人在术语层面达成共识\N{\fs12}So this is mostly kind of getting us all on the same page terminology-wise.
Dialogue: 0,0:14:18.50,0:14:21.59,yin,,0,0,0,,MVC 模型 视图 控制器\N{\fs12}So MVC, Model View Controller,
Dialogue: 0,0:14:21.59,0:14:28.50,yin,,0,0,0,,也就是一种将应用中所有类组织起来的策略\N{\fs12}is essentially a strategy for how to organize all the classes in your application.
Dialogue: 0,0:14:28.50,0:14:34.50,yin,,0,0,0,,这里我们会将所有类归到三块中\N{\fs12}And what we do fundamentally is we divide all the classes into one of three camps.
Dialogue: 0,0:14:34.50,0:14:38.50,yin,,0,0,0,,一块是模型 一块是控制器 一块是视图\N{\fs12}The model camp, the controller camp, or the view camp,
Dialogue: 0,0:14:38.50,0:14:41.50,yin,,0,0,0,,那你怎么知道哪个类属于哪一块呢\N{\fs12}and what, how you decide what goes in each of these camps,
Dialogue: 0,0:14:41.50,0:14:46.50,yin,,0,0,0,,模型实际上考虑的是「什么」的问题 程序是什么\N{\fs12}well, the model is essentially the what of your program. What is your program?
Dialogue: 0,0:14:46.50,0:14:50.31,yin,,0,0,0,,讲 MVC 时 我将讲到我们的第一个应用\N{\fs12}So, as we're doing this MVC talk, I'm going to talk about our first application
Dialogue: 0,0:14:50.31,0:14:52.50,yin,,0,0,0,,也就是一个纸牌匹配游戏\N{\fs12}we're going to build which is a card matching game.
Dialogue: 0,0:14:52.50,0:14:54.16,yin,,0,0,0,,我们将创建这个游戏\N{\fs12}Okay? So we're going to build this game,
Dialogue: 0,0:14:54.17,0:14:56.50,yin,,0,0,0,,它会在屏幕上给出一些纸牌\N{\fs12}it's gotta bunch of cards on the screen, like playing cards, you know,
Dialogue: 0,0:14:56.50,0:14:58.78,yin,,0,0,0,,比如梅花 A 这些\N{\fs12}Ace of Clubs and all that,
Dialogue: 0,0:14:58.78,0:15:01.50,yin,,0,0,0,,你需要选择一些纸牌\N{\fs12}and you're going to be able to go choose the cards
Dialogue: 0,0:15:01.50,0:15:03.50,yin,,0,0,0,,匹配上的话就能得分\N{\fs12}and you'll get certain points if the match.
Dialogue: 0,0:15:03.50,0:15:05.91,yin,,0,0,0,,如花色匹配或大小匹配这些\N{\fs12}Like the suit matches or the rank matches, or whatever,
Dialogue: 0,0:15:05.91,0:15:08.87,yin,,0,0,0,,或多或少 反正匹配上你就会得分\N{\fs12}you get more points, less points whatever, but you're doing that.
Dialogue: 0,0:15:08.87,0:15:11.28,yin,,0,0,0,,在这样的纸牌匹配小游戏中\N{\fs12}In that kind of application, a little card matching game,
Dialogue: 0,0:15:11.28,0:15:16.39,yin,,0,0,0,,纸牌 牌堆 甚至游戏玩法的逻辑\N{\fs12}the cards and the deck, and even the logic for how the game is played
Dialogue: 0,0:15:16.39,0:15:20.50,yin,,0,0,0,,都是独立于 UI 且在模型中的\N{\fs12}are all UI independent and in the model.
Dialogue: 0,0:15:21.50,0:15:25.50,yin,,0,0,0,,纸牌如何抽取到屏幕上是控制器的工作\N{\fs12}So how the cards get drawn on screen is the job of the controller.
Dialogue: 0,0:15:25.50,0:15:28.50,yin,,0,0,0,,控制器的任务是弄清如何\N{\fs12}So the controller is, its job is to figure out how am I going,
Dialogue: 0,0:15:28.50,0:15:31.50,yin,,0,0,0,,将这些牌显示在屏幕上\N{\fs12}you know, take this set of cards and display them on screen,
Dialogue: 0,0:15:31.50,0:15:35.50,yin,,0,0,0,,然后将其运动用动画形式展现出来 等等\N{\fs12}and then animate their movement and things like that.
Dialogue: 0,0:15:35.50,0:15:36.78,yin,,0,0,0,,这是控制器的工作\N{\fs12}Okay? That's up to the controller.
Dialogue: 0,0:15:36.79,0:15:41.50,yin,,0,0,0,,控制器控制模型如何呈现在屏幕上\N{\fs12}So the controller controls how the model is presented on screen,
Dialogue: 0,0:15:41.50,0:15:44.05,yin,,0,0,0,,而视图则是「仆从」\N{\fs12}and the view is the minions,
Dialogue: 0,0:15:44.05,0:15:46.31,yin,,0,0,0,,是控制器要使用的类\N{\fs12}the classes that the controller is going to use,
Dialogue: 0,0:15:46.31,0:15:48.50,yin,,0,0,0,,就像是林肯积木一样\N{\fs12}kind of like the building blocks, the Lincoln Logs,
Dialogue: 0,0:15:48.50,0:15:51.50,yin,,0,0,0,,这种积木对于你们而言可能已经有点过时了\N{\fs12}I don't know maybe that's before all your time, but, you know,
Dialogue: 0,0:15:51.50,0:15:56.07,yin,,0,0,0,,视图中的东西 会被用于构建 UI\N{\fs12}the things we're going to do build our UI we're going to use in the view,
Dialogue: 0,0:15:56.07,0:15:59.50,yin,,0,0,0,,视图中的东西非常通用\N{\fs12}so, the stuff that's in the view is pretty generic.
Dialogue: 0,0:15:59.50,0:16:01.22,yin,,0,0,0,,通用 UI 元素\N{\fs12}Generic UI elements,
Dialogue: 0,0:16:01.22,0:16:04.50,yin,,0,0,0,,而控制器中的东西非常特定地用于 UI 的工作\N{\fs12}the stuff in the controller is very specific to how your UI works,
Dialogue: 0,0:16:04.50,0:16:08.50,yin,,0,0,0,,而模型中的东西完全独立于 UI 的工作\N{\fs12}and the stuff in the model is completely independent of how your UI works.
Dialogue: 0,0:16:10.29,0:16:15.50,yin,,0,0,0,,把 MVC 弄对需要知道事物怎么运行\N{\fs12}So, doing MVC right is about knowing where things go,
Dialogue: 0,0:16:15.50,0:16:19.03,yin,,0,0,0,,还需要知道这三块之间如何通信\N{\fs12}but also about how to communicate between these three camps
Dialogue: 0,0:16:19.04,0:16:22.48,yin,,0,0,0,,我将概述这三者之间的通信方式\N{\fs12}and so I'm going to try and summarize how the communication works between these camps
Dialogue: 0,0:16:22.48,0:16:25.61,yin,,0,0,0,,这里我用了一些道路标识 我画了双黄线\N{\fs12}and I've used road markings, you see the double yellow line
Dialogue: 0,0:16:25.61,0:16:29.26,yin,,0,0,0,,还有白色虚线 就像你开车时看到的一样\N{\fs12}and then the dashed white line, so that's like you're driving in your car,
Dialogue: 0,0:16:29.26,0:16:34.20,yin,,0,0,0,,我打算这样来表示通信发生的方式\N{\fs12}try to use them as that I have an image for how this communication happens,
Dialogue: 0,0:16:34.20,0:16:36.55,yin,,0,0,0,,哪里允许 哪里不允许\N{\fs12}where it's allowed, where it's not allowed. Okay?
Dialogue: 0,0:16:36.55,0:16:39.96,yin,,0,0,0,,首先来看控制器同模型的通信\N{\fs12}So let's talk about the controller talking to the model.
Dialogue: 0,0:16:39.98,0:16:44.50,yin,,0,0,0,,从道路这一侧到模型这一侧是白色虚线\N{\fs12}Okay? Going from that side of the road over to the model side is a dashed white line,
Dialogue: 0,0:16:44.50,0:16:46.50,yin,,0,0,0,,也就是说 你可以直接通过\N{\fs12}in other words, you can head right across there,
Dialogue: 0,0:16:46.50,0:16:49.50,yin,,0,0,0,,也许过马路之前要先左右看看 但是能过\N{\fs12}you probably want to look before you go, but you can go right across.
Dialogue: 0,0:16:49.50,0:16:52.77,yin,,0,0,0,,控制器需要知道模型的一切\N{\fs12}The controller has to know everything about the model
Dialogue: 0,0:16:52.78,0:16:56.50,yin,,0,0,0,,还需要有同模型完全通信的能力\N{\fs12}and it has to have complete ability to talk to the model,
Dialogue: 0,0:16:56.50,0:16:58.96,yin,,0,0,0,,按照任何方式使用其公共 API\N{\fs12}use its public API as much as it wants,
Dialogue: 0,0:16:58.98,0:17:00.74,yin,,0,0,0,,因为控制器的工作\N{\fs12}because the controller's job is to
Dialogue: 0,0:17:00.74,0:17:05.11,yin,,0,0,0,,就是将模型呈现给用户 使用视图作为其仆从\N{\fs12}present the model to the user using its view as its minions,
Dialogue: 0,0:17:05.11,0:17:06.50,yin,,0,0,0,,它需要能够这样访问\N{\fs12}so it has to have this access.
Dialogue: 0,0:17:06.50,0:17:10.79,yin,,0,0,0,,控制器需要能够完全 不受限地访问模型\N{\fs12}So that's full, unrestricted access the controller has talking to the model.
Dialogue: 0,0:17:10.81,0:17:15.50,yin,,0,0,0,,这是从控制器到模型的单向箭头\N{\fs12}This is a one-way arrow, from the controller to the model.
Dialogue: 0,0:17:15.50,0:17:20.50,yin,,0,0,0,,类似地 从控制器到视图 通信也是不受限的\N{\fs12}And similarly from the controller to the view, is also unlimited communication
Dialogue: 0,0:17:20.50,0:17:24.37,yin,,0,0,0,,因为控制器需要随意使唤自己的仆从\N{\fs12}because the controller is responsible for talking, using, it's own minions,
Dialogue: 0,0:17:24.37,0:17:29.09,yin,,0,0,0,,视图是控制器的仆从 来布局用户界面这些\N{\fs12}the view is the controllers' minions to lay out the user interface and all that stuff,
Dialogue: 0,0:17:29.11,0:17:31.25,yin,,0,0,0,,控制器可以做任何事情\N{\fs12}so the controller can do anything it wants,
Dialogue: 0,0:17:31.26,0:17:33.50,yin,,0,0,0,,这里我用绿色写了一个词 outlet(出口)\N{\fs12}I've put that little green word outlet up there
Dialogue: 0,0:17:33.50,0:17:37.94,yin,,0,0,0,,因为当我们有这样一个属性 从控制器指向视图时\N{\fs12}because when we have a property of a controller that points into the view,
Dialogue: 0,0:17:37.94,0:17:39.50,yin,,0,0,0,,我们将它称作 outlet\N{\fs12}we call it an outlet.
Dialogue: 0,0:17:39.50,0:17:41.74,yin,,0,0,0,,这还会在周三的 demo 中出现\N{\fs12}Okay? And you're going to see that in the demo on Wednesday,
Dialogue: 0,0:17:41.76,0:17:45.24,yin,,0,0,0,,我会说 让我们创建一个从控制器到视图的 outlet\N{\fs12}I'm going to say oh, let's create an outlet from our controller to our view
Dialogue: 0,0:17:45.24,0:17:47.50,yin,,0,0,0,,这样控制器就能同视图通信\N{\fs12}so our controller can talk to its view.
Dialogue: 0,0:17:48.64,0:17:50.96,yin,,0,0,0,,从模型到视图的通信呢\N{\fs12}What about this communication? Model to view,
Dialogue: 0,0:17:50.96,0:17:53.07,yin,,0,0,0,,从不 为什么\N{\fs12}never, and why is that?
Dialogue: 0,0:17:53.09,0:17:56.92,yin,,0,0,0,,100% 明显 模型完全是独立于 UI 的\N{\fs12}100 percent obvious. The model is completely UI independent.
Dialogue: 0,0:17:56.94,0:18:01.50,yin,,0,0,0,,它绝对不能同视图这一块中的对象进行沟通\N{\fs12}So there's absolutely no way it could talk to a view or object or anyone in that camp.
Dialogue: 0,0:18:01.50,0:18:04.83,yin,,0,0,0,,因为视图对象本质上是 UI 对象 它们是通用的\N{\fs12}Because the view objects are fundamentally UI objects, they're kind of generic,
Dialogue: 0,0:18:04.83,0:18:06.98,yin,,0,0,0,,但它们仍然是 UI 对象\N{\fs12}but they're still fundamentally UI objects.
Dialogue: 0,0:18:07.00,0:18:09.50,yin,,0,0,0,,类似地 由于视图对象是通用的\N{\fs12}Similarly, since the view objects are kind of generic,
Dialogue: 0,0:18:09.50,0:18:11.50,yin,,0,0,0,,它们无法同任何特定模型通信\N{\fs12}they can't be talking to any specific model.
Dialogue: 0,0:18:11.50,0:18:15.50,yin,,0,0,0,,它们需要控制器来为它们解释模型\N{\fs12}They need a controller to interpret a model for them.
Dialogue: 0,0:18:15.50,0:18:19.50,yin,,0,0,0,,这里没有任何通信发生 所以我用双黄线\N{\fs12}Okay? So there's never any communication this way, that's why it's a double yellow line,
Dialogue: 0,0:18:19.50,0:18:23.50,yin,,0,0,0,,所以箭头是红色的 所以这里用着火表示\N{\fs12}that's why these lines are red, that's why there's fire.
Dialogue: 0,0:18:23.50,0:18:26.50,yin,,0,0,0,,绝对不能越过这条线\N{\fs12}Never go across that line, ever.
Dialogue: 0,0:18:27.66,0:18:29.98,yin,,0,0,0,,视图往回同控制器通信呢\N{\fs12}What about the view talking back to the controller?
Dialogue: 0,0:18:29.98,0:18:32.27,yin,,0,0,0,,这里有一些通用视图对象 如按钮\N{\fs12}You got these generic view objects, like buttons,
Dialogue: 0,0:18:32.27,0:18:34.03,yin,,0,0,0,,它们能同控制器通信吗\N{\fs12}can they talk to the controller?
Dialogue: 0,0:18:34.07,0:18:38.83,yin,,0,0,0,,确实 它们能 但这里要小心\N{\fs12}Well...yes, they can, but they have to be careful
Dialogue: 0,0:18:38.83,0:18:41.11,yin,,0,0,0,,因为视图对象是通用的\N{\fs12}because the view objects are generic,
Dialogue: 0,0:18:41.11,0:18:44.50,yin,,0,0,0,,所以它们不能对控制器知道得太多\N{\fs12}so they can't really know much about the controller, so,
Dialogue: 0,0:18:44.50,0:18:47.61,yin,,0,0,0,,它们只能以一种「盲」的方式同控制器通信\N{\fs12}they can only communicate back to the controller in a blind way,
Dialogue: 0,0:18:47.61,0:18:50.68,yin,,0,0,0,,它们不知道通信对方的类\N{\fs12}where they don't know the class of the thing they're talking to,
Dialogue: 0,0:18:50.68,0:18:52.50,yin,,0,0,0,,而且这里需要一种结构化方式\N{\fs12}and, in a structured way,
Dialogue: 0,0:18:52.50,0:18:56.07,yin,,0,0,0,,也就是说 我们都同意能够这样通信\N{\fs12}a way where we all agree, we're going to communicate this way,
Dialogue: 0,0:18:56.07,0:18:59.16,yin,,0,0,0,,视图和控制器之间的结构化通信有哪些例子呢\N{\fs12}between the view and the controller, so what's an example of a structured way?
Dialogue: 0,0:18:59.16,0:19:01.14,yin,,0,0,0,,一种叫作目标动作\N{\fs12}Well one is called target action.
Dialogue: 0,0:19:01.18,0:19:04.14,yin,,0,0,0,,控制器在自身身上设置一个目标\N{\fs12}So the controller basically drops a target on itself
Dialogue: 0,0:19:04.14,0:19:08.50,yin,,0,0,0,,它会提供一个动作 就像一支箭一样\N{\fs12}and then it hands out an action, which is like an arrow,
Dialogue: 0,0:19:08.50,0:19:11.35,yin,,0,0,0,,给到视图 对视图说\N{\fs12}to the view and says to the view, okay,
Dialogue: 0,0:19:11.35,0:19:14.48,yin,,0,0,0,,当你要做什么时 例如你是按钮 有人按了你\N{\fs12}when you do what you do, like you're a button and someone touches you
Dialogue: 0,0:19:14.48,0:19:18.50,yin,,0,0,0,,或你是滑动条 有人动了你 发送这个动作给我\N{\fs12}or you're a slider and someone moves you, send me that action.
Dialogue: 0,0:19:18.50,0:19:22.50,yin,,0,0,0,,通过这种方式 通用的按钮或滑动条\N{\fs12}Okay? So in this way, the generic button, or slider,
Dialogue: 0,0:19:22.50,0:19:26.10,yin,,0,0,0,,就能往回同控制器通信 它不知道这是纸牌游戏控制器\N{\fs12}is communicating back to the controller, it has no idea that it's a card game controller
Dialogue: 0,0:19:26.11,0:19:29.50,yin,,0,0,0,,还是空间游戏控制器 它不知道这是什么样的控制器\N{\fs12}or a space game controller, it doesn't know what kind of controller it is,
Dialogue: 0,0:19:29.50,0:19:32.16,yin,,0,0,0,,它只知道自身发生什么之后\N{\fs12}All it knows is that when something happens in itself,
Dialogue: 0,0:19:32.18,0:19:33.50,yin,,0,0,0,,将消息发给目标\N{\fs12}boom, it sends messages to targets.
Dialogue: 0,0:19:33.50,0:19:37.50,yin,,0,0,0,,这是一种盲的 简单的 结构化的方式 让视图\N{\fs12}So that's a blind, simple, structured way for the view
Dialogue: 0,0:19:37.50,0:19:40.18,yin,,0,0,0,,能够同控制器通信\N{\fs12}to communicate with the controller.
Dialogue: 0,0:19:40.18,0:19:42.50,yin,,0,0,0,,还有更复杂的方式吗\N{\fs12}But what about more complicated ways?
Dialogue: 0,0:19:42.50,0:19:47.42,yin,,0,0,0,,有时 视图中发生的情况会更复杂一些\N{\fs12}Sometimes the view, things are happening in the view that are somewhat complicated
Dialogue: 0,0:19:47.42,0:19:50.10,yin,,0,0,0,,而控制器需要知道发生了什么\N{\fs12}and the controller needs to be informed of what's going on,
Dialogue: 0,0:19:50.11,0:19:52.23,yin,,0,0,0,,同步获知发生了什么\N{\fs12}synchronizing what's happening.
Dialogue: 0,0:19:52.24,0:19:57.66,yin,,0,0,0,,一种考虑方法就是我这里写的几个单词 将要 应该 已经\N{\fs12}And one way to think about this is these words I put here, will, should, and did,
Dialogue: 0,0:19:57.66,0:20:01.68,yin,,0,0,0,,以滚动视图为例\N{\fs12}when the view is kind of like -- let's say on the scroll view
Dialogue: 0,0:20:01.68,0:20:05.50,yin,,0,0,0,,我在滚动 我想要控制器\N{\fs12}and I'm scrolling around, and I want to let the controller,
Dialogue: 0,0:20:05.50,0:20:09.50,yin,,0,0,0,,知道用户刚才「已经」滚动过\N{\fs12}somebody, know that the user just did scroll. Okay?
Dialogue: 0,0:20:09.50,0:20:12.73,yin,,0,0,0,,或者用户刚按到这里准备滚动\N{\fs12}Or the user puts down the touch and is about to scroll,
Dialogue: 0,0:20:12.74,0:20:16.50,yin,,0,0,0,,我要让控制器知道用户「将要」滚动\N{\fs12}I want to let the controller know the user will be scrolling.
Dialogue: 0,0:20:16.50,0:20:19.50,yin,,0,0,0,,或者当用户触碰到后 滚动视图想知道\N{\fs12}Okay? Or the user puts a touch down and the scroll view wants to know,
Dialogue: 0,0:20:19.50,0:20:23.50,yin,,0,0,0,,我「应该」允许滚动吗 这是允许的吗\N{\fs12}should I allow the user to scroll here, is that allowed?
Dialogue: 0,0:20:23.50,0:20:25.42,yin,,0,0,0,,所有这些问题\N{\fs12}All those things,
Dialogue: 0,0:20:25.42,0:20:29.50,yin,,0,0,0,,滚动视图自身都没有足够的逻辑去知道答案\N{\fs12}the scroll view itself might not have enough logic to know the answer to those questions,
Dialogue: 0,0:20:29.50,0:20:36.21,yin,,0,0,0,,于是它会将回答这些问题的权力委托给其它对象\N{\fs12}so what it does is it delegates the authority to answer those questions to some other object.
Dialogue: 0,0:20:36.22,0:20:38.20,yin,,0,0,0,,它不知道这一对象的类\N{\fs12}Now it doesn't know the class of that object,
Dialogue: 0,0:20:38.20,0:20:40.73,yin,,0,0,0,,它只知道这种对象能够回答这些问题\N{\fs12}all it knows is that other object can answer these questions,
Dialogue: 0,0:20:40.73,0:20:43.21,yin,,0,0,0,,将要 应该 已经做这个或那个\N{\fs12}will, should, did, this, that or the other thing,
Dialogue: 0,0:20:43.22,0:20:48.14,yin,,0,0,0,,例如应该允许滚动 已经滚动过 诸如此类\N{\fs12}like, should allow scrolling, did scroll to point, things like that.
Dialogue: 0,0:20:48.14,0:20:52.25,yin,,0,0,0,,这些就是这类委托协议中你们会看到的方法\N{\fs12}So those are the kind of methods you're going to see in these delegate protocols.
Dialogue: 0,0:20:52.25,0:20:55.90,yin,,0,0,0,,我知道 CS106A 和 B 课程没有讲授协议\N{\fs12}Now I know that CS106A&B do not teach protocols,
Dialogue: 0,0:20:55.90,0:20:59.50,yin,,0,0,0,,多少人知道面向对象编程中协议表示什么\N{\fs12}how many people know what the word protocol means in object-oriented programming?
Dialogue: 0,0:20:59.50,0:21:02.50,yin,,0,0,0,,很少有人 那我就来讲了\N{\fs12}See, very few of you, so I will be teaching that.
Dialogue: 0,0:21:02.50,0:21:05.50,yin,,0,0,0,,协议是一种同另一对象通信的盲方式\N{\fs12}A protocol is just a blind way to talk to another object.
Dialogue: 0,0:21:05.50,0:21:08.50,yin,,0,0,0,,我给你讲时 你可能会想 哦 对 我知道这个\N{\fs12}You're going, when I teach you, you're going to be like, oh yeah, I know what that is,
Dialogue: 0,0:21:08.50,0:21:10.50,yin,,0,0,0,,我们不叫它协议 等等\N{\fs12}we didn't really call it protocol, or whatever.
Dialogue: 0,0:21:10.50,0:21:15.50,yin,,0,0,0,,不过 这就是我们进行委托的方式 这种盲的通信\N{\fs12}But, that's how we do delegation, this blind communication.
Dialogue: 0,0:21:15.50,0:21:18.50,yin,,0,0,0,,另外还有一点很重要\N{\fs12}Also, another important thing is
Dialogue: 0,0:21:18.50,0:21:22.90,yin,,0,0,0,,视图不应该「拥有」它们所显示的数据\N{\fs12}that views should not own the data that they're displaying. They should not own it.
Dialogue: 0,0:21:22.90,0:21:25.94,yin,,0,0,0,,也就是说 数据不应该是它们内部的属性\N{\fs12}In other words, it shouldn't be a property inside of them
Dialogue: 0,0:21:25.94,0:21:28.25,yin,,0,0,0,,数据是数据\N{\fs12}where that's the truth of that data.
Dialogue: 0,0:21:28.25,0:21:30.70,yin,,0,0,0,,最简单的例子是\N{\fs12}And the easiest example for this is
Dialogue: 0,0:21:30.70,0:21:34.29,yin,,0,0,0,,iPod iPhone 或 iPad 中的所有歌曲\N{\fs12}all the songs in your iPod, on your iPhone or your iPad, right?
Dialogue: 0,0:21:34.29,0:21:37.05,yin,,0,0,0,,你可能有一万首歌\N{\fs12}You might have 10,000 songs in there.
Dialogue: 0,0:21:37.05,0:21:40.50,yin,,0,0,0,,如果你有某种通用的列表视图在视图中\N{\fs12}So if you have some kind of generic list view in your view,
Dialogue: 0,0:21:40.50,0:21:44.99,yin,,0,0,0,,你不能将一万首歌转给它的实例变量\N{\fs12}you can't transfer all 10,000 songs to its instance variables
Dialogue: 0,0:21:44.99,0:21:48.50,yin,,0,0,0,,指望它能容纳一万首歌 然后逐个列出\N{\fs12}and expect it to hold 10,000 songs so it can list through it.
Dialogue: 0,0:21:48.50,0:21:50.40,yin,,0,0,0,,一 这很低效\N{\fs12}A, that would be inefficient,
Dialogue: 0,0:21:50.40,0:21:54.29,yin,,0,0,0,,二 这一万首歌属于哪里\N{\fs12}and B, that information, those 10,000 songs belongs where?
Dialogue: 0,0:21:54.70,0:21:55.88,yin,,0,0,0,,在模型里\N{\fs12}In the model.
Dialogue: 0,0:21:55.90,0:21:58.50,yin,,0,0,0,,因为音乐数据库是一个模型\N{\fs12}Because your song database is a model.
Dialogue: 0,0:21:58.50,0:22:02.14,yin,,0,0,0,,它无关于 UI 只是一个歌曲 艺术家 专辑列表\N{\fs12}It has nothing to do with UI's, just a list of songs and artists and albums and all that,
Dialogue: 0,0:22:02.14,0:22:03.31,yin,,0,0,0,,这在模型中\N{\fs12}it's in the model.
Dialogue: 0,0:22:03.31,0:22:05.50,yin,,0,0,0,,某控制器需要访问这个数据库\N{\fs12}Some controller has to look at that database
Dialogue: 0,0:22:05.50,0:22:09.77,yin,,0,0,0,,告诉视图如何显示这些歌曲\N{\fs12}and tell a view how to display all those songs.
Dialogue: 0,0:22:09.77,0:22:13.05,yin,,0,0,0,,我们需要这种通信在这里发生\N{\fs12}So, we need that communication to happen here
Dialogue: 0,0:22:13.07,0:22:15.50,yin,,0,0,0,,而视图要呈现某种列表\N{\fs12}and the view is displaying some sort of list,
Dialogue: 0,0:22:15.50,0:22:18.50,yin,,0,0,0,,你触控屏幕 轻按打开列表\N{\fs12}and you're touching down and you're flicking on the list
Dialogue: 0,0:22:18.50,0:22:20.16,yin,,0,0,0,,试图看到更多歌曲\N{\fs12}and trying to see more songs,
Dialogue: 0,0:22:20.16,0:22:23.05,yin,,0,0,0,,这种互动如何进行 答案是\N{\fs12}how does that communication happen, and the answer is,
Dialogue: 0,0:22:23.07,0:22:25.50,yin,,0,0,0,,我们另一种特殊的委托\N{\fs12}we have another special kind of delegate,
Dialogue: 0,0:22:25.50,0:22:27.50,yin,,0,0,0,,我们称之为数据源\N{\fs12}which we call a data source.
Dialogue: 0,0:22:27.50,0:22:30.50,yin,,0,0,0,,数据源不会考虑将要 已经 应该\N{\fs12}Now the data source doesn't do the will, did, should,
Dialogue: 0,0:22:30.50,0:22:32.50,yin,,0,0,0,,它会要求计数这些\N{\fs12}it's going to be asking questions like count,
Dialogue: 0,0:22:32.50,0:22:34.50,yin,,0,0,0,,例如有多少歌曲\N{\fs12}like how many songs are there?
Dialogue: 0,0:22:34.50,0:22:37.50,yin,,0,0,0,,控制器去模型中看 一万\N{\fs12}And the controller looks in the model, 10,000.
Dialogue: 0,0:22:37.50,0:22:39.50,yin,,0,0,0,,回给视图 有一万首\N{\fs12}Response to the view, there's 10,000.
Dialogue: 0,0:22:39.50,0:22:42.86,yin,,0,0,0,,视图会在内部预留一万个事物的空间\N{\fs12}The view makes space, internally, for 10,000 things,
Dialogue: 0,0:22:42.86,0:22:43.95,yin,,0,0,0,,它不知道具体是什么\N{\fs12}it doesn't know what they are,
Dialogue: 0,0:22:43.97,0:22:46.50,yin,,0,0,0,,将滚动条指示器移动一些\N{\fs12}moves the scroll bar indicator a little bit,
Dialogue: 0,0:22:46.50,0:22:48.01,yin,,0,0,0,,这样你就知道在哪\N{\fs12}so that you know where it is,
Dialogue: 0,0:22:48.01,0:22:50.29,yin,,0,0,0,,然后你开始滚动翻阅\N{\fs12}and then you start scrolling, flipping through it,
Dialogue: 0,0:22:50.29,0:22:52.08,yin,,0,0,0,,然后它开始向控制器发送消息\N{\fs12}and its start sending the message to the controller,
Dialogue: 0,0:22:52.08,0:22:57.51,yin,,0,0,0,,例如 给我第 150 行处的数据 后面 10 个项目\N{\fs12}give me the data at line 150, next 10 items.
Dialogue: 0,0:22:57.53,0:22:59.56,yin,,0,0,0,,明白吗 然后你继续往下 它会要求\N{\fs12}See what I mean? And then you flick down some more, now it's saying
Dialogue: 0,0:22:59.57,0:23:02.01,yin,,0,0,0,,250 行处的后面 10 个项目\N{\fs12}250, 10 more items,
Dialogue: 0,0:23:02.01,0:23:05.34,yin,,0,0,0,,控制器会回到模型 要求更多数据\N{\fs12}and so the controller is going back to the model and saying give me more, give me more data,
Dialogue: 0,0:23:05.34,0:23:07.88,yin,,0,0,0,,它会以这种盲的方式提供给视图\N{\fs12}and it's providing it to the view in this blind way.
Dialogue: 0,0:23:07.90,0:23:12.03,yin,,0,0,0,,这就是视图通过控制器从模型获取数据的方式\N{\fs12}So see how the view is getting data from the model through the controller,
Dialogue: 0,0:23:12.03,0:23:14.47,yin,,0,0,0,,这是一种盲的结构化方式\N{\fs12}in this kind of blind structured way.
Dialogue: 0,0:23:14.49,0:23:16.92,yin,,0,0,0,,大家都明白了吗\N{\fs12}Okay? That makes sense to everybody?
Dialogue: 0,0:23:16.94,0:23:18.97,yin,,0,0,0,,数据源其实是一种委托\N{\fs12}So data source is just a kind of delegate,
Dialogue: 0,0:23:18.97,0:23:20.88,yin,,0,0,0,,它是一类用于获取数据的特殊委托\N{\fs12}it's a specific kind of delegate for getting data.
Dialogue: 0,0:23:20.88,0:23:24.95,yin,,0,0,0,,你们会看到 iOS 中有一些类具有数据源\N{\fs12}So you're going to see that there are classes in iOS that have a data source,
Dialogue: 0,0:23:24.95,0:23:27.16,yin,,0,0,0,,它们通常也还有委托\N{\fs12}and they usually also have a delegate.
Dialogue: 0,0:23:27.18,0:23:29.68,yin,,0,0,0,,iOS 中大多数精密的类中都有委托\N{\fs12}Most sophisticated classes in iOS have a delegate,
Dialogue: 0,0:23:29.68,0:23:31.50,yin,,0,0,0,,将要 已经 应该这类东西\N{\fs12}the will, did, should kind of things.
Dialogue: 0,0:23:31.50,0:23:33.80,yin,,0,0,0,,有些类中还有数据源\N{\fs12}Some of them have a data source,
Dialogue: 0,0:23:33.81,0:23:36.73,yin,,0,0,0,,取决于它们是不是要展示出数据\N{\fs12}it depends on whether they're showing a lot of data or not.
Dialogue: 0,0:23:36.75,0:23:38.77,yin,,0,0,0,,简单数据 比如某个视图\N{\fs12}Now simple data, like if I had a view,
Dialogue: 0,0:23:38.77,0:23:42.50,yin,,0,0,0,,我在纸牌游戏中创建了一个视图叫 PlayingCard\N{\fs12}if I invented a view for my card game called playing card view,
Dialogue: 0,0:23:42.50,0:23:44.79,yin,,0,0,0,,它只有花色和大小\N{\fs12}and it just has a suit and a rank,
Dialogue: 0,0:23:44.79,0:23:47.86,yin,,0,0,0,,我们不会对花色和大小进行数据计数\N{\fs12}okay, we're not going to do count data at for just suit and rank,
Dialogue: 0,0:23:47.86,0:23:49.50,yin,,0,0,0,,我们会把它们设为属性\N{\fs12}we are going to set those properties.
Dialogue: 0,0:23:49.50,0:23:52.79,yin,,0,0,0,,视图中会设置有这些数据\N{\fs12}And so the view then would have those, that data set in it,
Dialogue: 0,0:23:52.79,0:23:55.06,yin,,0,0,0,,但它并不「拥有」它\N{\fs12}but it wouldn't be owning it, right?
Dialogue: 0,0:23:55.08,0:23:57.50,yin,,0,0,0,,模型仍然拥有花色和大小\N{\fs12}The model would still be owning the suit and rank,
Dialogue: 0,0:23:57.50,0:24:00.50,yin,,0,0,0,,视图只获得数据来进行显示\N{\fs12}the view is just getting that data to present it.
Dialogue: 0,0:24:00.50,0:24:06.50,yin,,0,0,0,,简单数据可以转给视图 但这只是给视图来显示\N{\fs12}So simple data we might transfer to the view, but it's merely for it to display it.
Dialogue: 0,0:24:06.50,0:24:12.17,yin,,0,0,0,,好 所有这些说的是 控制器的工作是为视图\N{\fs12}Okay. This all adds up to the controller's job being to interpret
Dialogue: 0,0:24:12.18,0:24:16.14,yin,,0,0,0,,解释并格式化提供模型数据\N{\fs12}and format the model data for the view.
Dialogue: 0,0:24:16.14,0:24:17.50,yin,,0,0,0,,这是控制器的工作\N{\fs12}That's the controller's job.
Dialogue: 0,0:24:17.50,0:24:20.50,yin,,0,0,0,,我们讲 demo 时 我会提醒你们注意\N{\fs12}And when we do our demo, I'm going to be marking
Dialogue: 0,0:24:20.50,0:24:22.50,yin,,0,0,0,,我写这些代码\N{\fs12}like, oh, see, I'm writing this code,
Dialogue: 0,0:24:22.50,0:24:25.12,yin,,0,0,0,,是为了让控制器执行它的工作\N{\fs12}this makes the controller perform its job,
Dialogue: 0,0:24:25.12,0:24:28.99,yin,,0,0,0,,也就是将模型数据用到视图中\N{\fs12}which is to take the model data and put it in, and using it to view minions,
Dialogue: 0,0:24:28.99,0:24:30.50,yin,,0,0,0,,然后显示到屏幕上\N{\fs12}put it on screen.
Dialogue: 0,0:24:30.50,0:24:32.25,yin,,0,0,0,,这就是控制器的作用\N{\fs12}That's what the controller does.
Dialogue: 0,0:24:32.25,0:24:36.50,yin,,0,0,0,,那从模型到控制器的通信呢\N{\fs12}What about this communication? Can the model talk to the controller?
Dialogue: 0,0:24:36.50,0:24:41.16,yin,,0,0,0,,还是一样 这显然也是不允许的 因为模型对UI一无所知\N{\fs12}Again, obviously that's verboten because model knows nothing about UI,
Dialogue: 0,0:24:41.17,0:24:44.23,yin,,0,0,0,,所以它不能同控制器这样的 UI 对象进行通信\N{\fs12}so it couldn't possibly talk to a UI object like the controller.
Dialogue: 0,0:24:44.23,0:24:46.50,yin,,0,0,0,,但有时 模型中的事物会发生变化\N{\fs12}But sometimes things change in the model
Dialogue: 0,0:24:46.50,0:24:48.08,yin,,0,0,0,,控制器需要知道它\N{\fs12}and the controller needs to know about it.
Dialogue: 0,0:24:48.10,0:24:52.50,yin,,0,0,0,,例如数据变化 数据库变化 或者模型是某种网络数据库\N{\fs12}Okay, data changes, a database changes or the model is some network database
Dialogue: 0,0:24:52.50,0:24:54.77,yin,,0,0,0,,某人改变了网络上的东西 造成它变化\N{\fs12}and somebody changes something on the network and it changes,
Dialogue: 0,0:24:54.79,0:24:56.50,yin,,0,0,0,,控制器需要知道这些\N{\fs12}and the controller needs to find out. So,
Dialogue: 0,0:24:56.50,0:24:59.50,yin,,0,0,0,,这种通信如何做到呢\N{\fs12}how do we do that communication?
Dialogue: 0,0:24:59.50,0:25:06.50,yin,,0,0,0,,这可以通过一种电台的概念来理解\N{\fs12}We do that using kind of a radio station model. So the model, a radio station concept,
Dialogue: 0,0:25:06.50,0:25:12.50,yin,,0,0,0,,模型会使用这一概念来广播信息\N{\fs12}the model will use this concept to essentially broadcast information
Dialogue: 0,0:25:12.50,0:25:14.50,yin,,0,0,0,,给任何感兴趣的人\N{\fs12}to anyone who's interested.
Dialogue: 0,0:25:14.50,0:25:18.77,yin,,0,0,0,,iOS 中执行这一功能的叫作通知\N{\fs12}And the mechanisms for doing this in iOS are called notification
Dialogue: 0,0:25:18.77,0:25:21.86,yin,,0,0,0,,和键值观察 键值观察简称 KVO\N{\fs12}and key value observing, KVO we call it,
Dialogue: 0,0:25:21.86,0:25:24.50,yin,,0,0,0,,模型可以说 哦\N{\fs12}and so the model can just say, oh,
Dialogue: 0,0:25:24.50,0:25:28.50,yin,,0,0,0,,模型中任何东西发生变化 我会通过我的电台进行广播\N{\fs12}anytime something changes in my model, I'm just going to broadcast on my radio station
Dialogue: 0,0:25:28.50,0:25:32.50,yin,,0,0,0,,然后控制器会接收来自电台的信息\N{\fs12}and then the controller simply tunes into that radio station.
Dialogue: 0,0:25:32.50,0:25:35.50,yin,,0,0,0,,它会发现事物正在变化 发现事物变化时\N{\fs12}And it can find out things are changing. And when it finds out something changes,
Dialogue: 0,0:25:35.50,0:25:39.50,yin,,0,0,0,,它会通过它的绿箭头同模型通信\N{\fs12}it's going to communicate via its green arrow to the model,
Dialogue: 0,0:25:39.50,0:25:42.50,yin,,0,0,0,,让模型把变化了的数据给它\N{\fs12}and say, okay, give me that data that changed.
Dialogue: 0,0:25:42.50,0:25:44.30,yin,,0,0,0,,能理解吗\N{\fs12}Alright? Does that make sense?
Dialogue: 0,0:25:44.30,0:25:45.50,yin,,0,0,0,,学期最后\N{\fs12}So towards the end of the quarter,
Dialogue: 0,0:25:45.50,0:25:48.71,yin,,0,0,0,,我们将会看到 例如通知如何知道\N{\fs12}we'll start seeing a little how to do notification to find out, for example,
Dialogue: 0,0:25:48.71,0:25:50.84,yin,,0,0,0,,数据库中的数据变化了\N{\fs12}if the data in the database changes.
Dialogue: 0,0:25:50.86,0:25:53.50,yin,,0,0,0,,我们获得通知 UI 然后\N{\fs12}We'll get a notification, the UI can then, you know,
Dialogue: 0,0:25:53.50,0:25:58.50,yin,,0,0,0,,控制器然后能够到模型去获取信息\N{\fs12}the controller can then go talk to the model to get the info.
Dialogue: 0,0:25:58.50,0:26:01.50,yin,,0,0,0,,有人问 视图能否接收电台信号\N{\fs12}Some people have asked, can a view tune into the radio station?
Dialogue: 0,0:26:01.50,0:26:04.50,yin,,0,0,0,,它们也许能 但你最好不要这样做\N{\fs12}They probably could, but you probably wouldn't want to do that.
Dialogue: 0,0:26:04.50,0:26:07.50,yin,,0,0,0,,这可能会违反 MVC\N{\fs12}That would probably be a violation of MVC.
Dialogue: 0,0:26:07.50,0:26:13.56,yin,,0,0,0,,好 我们这样做 我们有这些很好的通信和规则\N{\fs12}Alright, so, we do this, we have all this nice communication and all these rules,
Dialogue: 0,0:26:13.56,0:26:17.38,yin,,0,0,0,,我们可以设想使用这个创建一些简单的程序\N{\fs12}and we can imagine building something simple using this,
Dialogue: 0,0:26:17.38,0:26:19.86,yin,,0,0,0,,但如果我们想创建更大更复杂的 app 呢\N{\fs12}but what if we want to build a big, complicated app?
Dialogue: 0,0:26:19.88,0:26:23.23,yin,,0,0,0,,在 iPhone 或 iPad 上具有多屏幕的 app\N{\fs12}An app that has multiple screens on our iPhone or on an iPad
Dialogue: 0,0:26:23.23,0:26:26.50,yin,,0,0,0,,例如屏幕上有三四个不同区域\N{\fs12}it's got, you know, three or four different areas on screen
Dialogue: 0,0:26:26.50,0:26:28.97,yin,,0,0,0,,在发生着事情 如何做到呢\N{\fs12}where things are happening, how do we do that?
Dialogue: 0,0:26:28.99,0:26:33.50,yin,,0,0,0,,我们会合并多个 MVC\N{\fs12}Well, we're essentially going to combine multiple MVC's.
Dialogue: 0,0:26:33.50,0:26:40.50,yin,,0,0,0,,因为 MVC 能够将另一 MVC 作为其视图的一部分\N{\fs12}Because you, an MVC can use, as part of its view, another MVC.
Dialogue: 0,0:26:40.50,0:26:44.50,yin,,0,0,0,,所以 一整个 MVC\N{\fs12}Okay? So, an MVC, an entire MVC,
Dialogue: 0,0:26:44.50,0:26:49.60,yin,,0,0,0,,可以作为另一个较大 MVC 的仆从\N{\fs12}can be one of the minions of some bigger MVC.
Dialogue: 0,0:26:49.62,0:26:53.15,yin,,0,0,0,,这样可以一直往下串联\N{\fs12}Okay? And by doing that and cascading it down,
Dialogue: 0,0:26:53.15,0:26:55.89,yin,,0,0,0,,你就能创建越来越复杂的应用\N{\fs12}we can build more and more complicated applications. So,
Dialogue: 0,0:26:55.91,0:27:01.15,yin,,0,0,0,,例如 你可以有一个日历 app\N{\fs12}an example of this is you might have your calendar app,
Dialogue: 0,0:27:01.15,0:27:03.54,yin,,0,0,0,,它会显示出一整年\N{\fs12}and it's showing you the entire year,
Dialogue: 0,0:27:03.54,0:27:06.19,yin,,0,0,0,,你点击月 这时就会显示出月视图\N{\fs12}and you click on a month, and now it shows you a month view.
Dialogue: 0,0:27:06.19,0:27:08.50,yin,,0,0,0,,月视图会非常不同于年视图\N{\fs12}Well a month view looks a lot different than a year view.
Dialogue: 0,0:27:08.50,0:27:11.50,yin,,0,0,0,,月视图上有日期和一些圈\N{\fs12}Month view just has all the days and maybe some circle
Dialogue: 0,0:27:11.50,0:27:13.23,yin,,0,0,0,,告诉你哪天有预约\N{\fs12}that tells you where you have an appointment on a day,
Dialogue: 0,0:27:13.25,0:27:16.50,yin,,0,0,0,,然后点击日期 你会得到日视图\N{\fs12}and then when you click on a day, and now you get a day view.
Dialogue: 0,0:27:16.50,0:27:20.00,yin,,0,0,0,,日视图会显示给你不同时间的预约\N{\fs12}And the day is showing you the hours and what all your appointments are,
Dialogue: 0,0:27:20.01,0:27:22.50,yin,,0,0,0,,点击某一预约 你会进入预约视图\N{\fs12}and you click on an appointment, and now you get an appointment view
Dialogue: 0,0:27:22.50,0:27:25.50,yin,,0,0,0,,它会显示给你具体细节 包括时间地点这些\N{\fs12}and it's showing the detail of where you're going and when it is etc.
Dialogue: 0,0:27:25.50,0:27:29.02,yin,,0,0,0,,所有这些视图 年视图 月视图\N{\fs12}Well each of those views, the year view, the month view,
Dialogue: 0,0:27:29.02,0:27:33.50,yin,,0,0,0,,日视图 预约视图都是自身的 MVC\N{\fs12}the day view, and the appointment view are their own MVC's.
Dialogue: 0,0:27:33.50,0:27:38.32,yin,,0,0,0,,但是你可以看到 后三个视图被用作\N{\fs12}Okay? But you can see how the last three, okay, are used as,
Dialogue: 0,0:27:38.32,0:27:44.50,yin,,0,0,0,,顶级视图 即年视图的仆从 用以显示更多细节\N{\fs12}essentially, a minion of the top-level view, the year view, to show more detail.
Dialogue: 0,0:27:44.50,0:27:46.50,yin,,0,0,0,,年视图 你点击一个月\N{\fs12}So the year view, you click on a month,
Dialogue: 0,0:27:46.50,0:27:51.02,yin,,0,0,0,,它会使用一个月视图 MVC 来显示更多细节\N{\fs12}it's going to use the month view MVC to show more detail,
Dialogue: 0,0:27:51.04,0:27:53.50,yin,,0,0,0,,这是年视图的一部分\N{\fs12}so it's part of its view.
Dialogue: 0,0:27:53.50,0:27:57.50,yin,,0,0,0,,iOS 中这还被用于标签栏控制器\N{\fs12}So, you see this also in iOS with tab bar controllers.
Dialogue: 0,0:27:57.50,0:28:01.52,yin,,0,0,0,,标签栏列在下方 有四五个可以选\N{\fs12}You have the tab bar, along the bottom, I have four or five things you can choose,
Dialogue: 0,0:28:01.52,0:28:03.50,yin,,0,0,0,,上方有一些 MVC\N{\fs12}well there's some MVC at the top
Dialogue: 0,0:28:03.50,0:28:06.50,yin,,0,0,0,,它有四个指针指向四个仆从\N{\fs12}who has four pointers to four minions,
Dialogue: 0,0:28:06.50,0:28:11.06,yin,,0,0,0,,也就是四个出现在标签栏中的 MVC\N{\fs12}which are the four MVC's that are each going to appear in a tab bar.
Dialogue: 0,0:28:11.06,0:28:14.19,yin,,0,0,0,,我们在作业二或三中可能会做这个\N{\fs12}We'll be doing that, for example, in assignment number two or three,
Dialogue: 0,0:28:14.19,0:28:18.50,yin,,0,0,0,,我们会制作标签栏 你们需要使用多 MVC\N{\fs12}where we'll be making a tab bar and you're going to have to do multiple MVC's.
Dialogue: 0,0:28:18.50,0:28:23.50,yin,,0,0,0,,这就得到了一个大致是这样的图像\N{\fs12}So, that basically results in a picture that looks kind of like this.
Dialogue: 0,0:28:23.50,0:28:29.24,yin,,0,0,0,,这里有一个 MVC 看到 together 下的紫色那个了吗\N{\fs12}Alright? Where you got this MVC and you see the purple one that's like underneath the word together there,
Dialogue: 0,0:28:29.25,0:28:34.50,yin,,0,0,0,,它从视图指向三个其它 MVC\N{\fs12}and it points to three other MVC's outside of its view thing.
Dialogue: 0,0:28:34.50,0:28:37.50,yin,,0,0,0,,这就是我们创建标签栏控制器的方式\N{\fs12}That's how we're going to build this, that might be a tab bar controller
Dialogue: 0,0:28:37.50,0:28:39.50,yin,,0,0,0,,这些可能就是三个标签\N{\fs12}and those might be the three tabs.
Dialogue: 0,0:28:39.50,0:28:43.82,yin,,0,0,0,,每一个都是自己的 MVC 完全独立运行\N{\fs12}And each one is its own little MVC, completely independent, operates on its own,
Dialogue: 0,0:28:43.84,0:28:48.13,yin,,0,0,0,,这时它就是一个类似于通用 可重用视图的东西\N{\fs12}doesn't even know it's a generic, reusable view like thing at this point,
Dialogue: 0,0:28:48.13,0:28:50.50,yin,,0,0,0,,它甚至不知道它在标签栏中\N{\fs12}it doesn't even know that it's in a tab bar.
Dialogue: 0,0:28:50.50,0:28:53.10,yin,,0,0,0,,它只知道要做自己该做的事\N{\fs12}It just knows that it's supposed to do whatever it does.
Dialogue: 0,0:28:53.10,0:28:54.82,yin,,0,0,0,,这方面来看 它是模块化的\N{\fs12}And so it's modular in that way.
Dialogue: 0,0:28:54.82,0:28:58.50,yin,,0,0,0,,可以看到 这里不再有其它箭头\N{\fs12}You can also see that there's no communication between any other,
Dialogue: 0,0:28:58.50,0:29:01.12,yin,,0,0,0,,除了一些模型\N{\fs12}there's no other arrows, except for some of the models.
Dialogue: 0,0:29:01.13,0:29:03.50,yin,,0,0,0,,某些模型之间在相互通信\N{\fs12}You see some of the models are communicating with each other,
Dialogue: 0,0:29:03.50,0:29:07.11,yin,,0,0,0,,要知道 一个大的应用也许会有一单个共享的模型\N{\fs12}you know, a big application might have single, shared model.
Dialogue: 0,0:29:07.12,0:29:13.69,yin,,0,0,0,,或者 模型会被划分开来给子 MVC 使用\N{\fs12}Or, you know, the models might be split off into pieces to be used by sub MVC's.
Dialogue: 0,0:29:13.71,0:29:16.15,yin,,0,0,0,,但这里就只有这种通信了\N{\fs12}But that's the only kind of communication you're going to have there,
Dialogue: 0,0:29:16.15,0:29:20.17,yin,,0,0,0,,其它通信要么是我们看过的 MVC 中的结构化通信\N{\fs12}all other communication is either the structured communication we saw in the MVC
Dialogue: 0,0:29:20.17,0:29:24.50,yin,,0,0,0,,要么是将 MVC 用作另一个 MVC 视图的一部分\N{\fs12}or it's using MVC's as part of the view of another MVC.
Dialogue: 0,0:29:24.50,0:29:27.50,yin,,0,0,0,,关于这个有问题吗\N{\fs12}Any question about that?
Dialogue: 0,0:29:27.50,0:29:31.84,yin,,0,0,0,,当然 我们显然不希望设计像这样乱糟糟\N{\fs12}So we definitely don't want to be having designs that look like this.
Dialogue: 0,0:29:31.84,0:29:35.04,yin,,0,0,0,,所有人都在相互通信 我们不知道谁和什么在通信\N{\fs12}Where everybody's talking to everybody, we can't tell who's talking to what,
Dialogue: 0,0:29:35.04,0:29:38.50,yin,,0,0,0,,这无疑让程序调试变得很难 而且这无法规模化\N{\fs12}it's just impossible to debug a program like this and it doesn't scale.
Dialogue: 0,0:29:38.50,0:29:40.50,yin,,0,0,0,,你无法像这样创建出大程序\N{\fs12}You can't build really big programs this way,
Dialogue: 0,0:29:40.50,0:29:44.50,yin,,0,0,0,,这样做的话 你永远无法弄清什么地方容易崩溃掉\N{\fs12}it just becomes impossible to know how touching anything would break everything, right?
Dialogue: 0,0:29:44.50,0:29:48.50,yin,,0,0,0,,所以 我们肯定不要这样做\N{\fs12}So we're definitely not going to be doing that.
Dialogue: 0,0:29:50.21,0:29:53.50,yin,,0,0,0,,这是 MVC 关于这方面有问题吗\N{\fs12}Okay, so that's MVC. No questions about that?
Dialogue: 0,0:29:53.50,0:29:55.73,yin,,0,0,0,,好 再看 Objective-C\N{\fs12}Alright. Onto objective-C.
Dialogue: 0,0:29:55.74,0:29:59.32,yin,,0,0,0,,Objective-C 是 C 的严格父集\N{\fs12}So, objective C is a strict superset of C,
Dialogue: 0,0:29:59.32,0:30:02.50,yin,,0,0,0,,C 中能做的事 Objective-C 中都能做\N{\fs12}so everything you can do in C, you can do in objective-C.
Dialogue: 0,0:30:02.50,0:30:05.50,yin,,0,0,0,,这门课中我们会做很多 C 方面的事情\N{\fs12}And we'll do a lot of C things in this class.
Dialogue: 0,0:30:05.50,0:30:10.50,yin,,0,0,0,,我们也会做很多面向对象的东西 但 C 也会经常用到\N{\fs12}We'll do a lot of object-oriented stuff too, but we're going to do a lot of C things, as well.
Dialogue: 0,0:30:10.50,0:30:14.50,yin,,0,0,0,,但这里显然有些东西你们需要改变思考方式\N{\fs12}But, there's obviously a few things that you want to think differently
Dialogue: 0,0:30:14.50,0:30:17.98,yin,,0,0,0,,毕竟这里有面向对象性加入到一个语言中\N{\fs12}about because you have object-oriented stuff added onto a language,
Dialogue: 0,0:30:17.98,0:30:20.13,yin,,0,0,0,,今天我会讲到其中一点\N{\fs12}and we're going to talk about one of them today,
Dialogue: 0,0:30:20.15,0:30:24.50,yin,,0,0,0,,除了我会展示的一些语法外\N{\fs12}in addition to showing you a little bit of the syntax,
Dialogue: 0,0:30:24.50,0:30:26.39,yin,,0,0,0,,我会谈到 Objective-C 中不同于\N{\fs12}we're going to talk about one of these different,
Dialogue: 0,0:30:26.39,0:30:29.32,yin,,0,0,0,,我会谈到 Objective-C 中不同于\N{\fs12}think differently things about objective-C that's different
Dialogue: 0,0:30:29.32,0:30:33.11,yin,,0,0,0,,C++ 或 Java 的内容 也就是属性\N{\fs12}than C++ or Java, which is properties.
Dialogue: 0,0:30:33.11,0:30:36.26,yin,,0,0,0,,这些我就不读了 我会展示给你们\N{\fs12}And I'm not going to read through all of this, I'm just going to show it to you,
Dialogue: 0,0:30:36.26,0:30:40.50,yin,,0,0,0,,属性是我们访问实例变量的方式\N{\fs12}but properties are basically how we access our instance variables.
Dialogue: 0,0:30:40.50,0:30:45.30,yin,,0,0,0,,大家都懂吗 知道实例变量的请举手\N{\fs12}Everybody knows what I mean by, raise your hand if you know what I mean by instance variable?
Dialogue: 0,0:30:45.30,0:30:47.17,yin,,0,0,0,,很好 基本上所有人都懂\N{\fs12}Okay good. So pretty much everybody.
Dialogue: 0,0:30:47.17,0:30:52.50,yin,,0,0,0,,我们希望访问对象的实例数据\N{\fs12}So, we want to access the instance data of our objects.
Dialogue: 0,0:30:52.50,0:30:56.50,yin,,0,0,0,,通常 在 Java 或 C++ 中 你只需要\N{\fs12}And, normally, in Java or in C++, you just,
Dialogue: 0,0:30:56.50,0:31:00.50,yin,,0,0,0,,有一些访问它们的语法 然后访问它们\N{\fs12}have some syntax to access them and you just access them.
Dialogue: 0,0:31:00.50,0:31:02.50,yin,,0,0,0,,在 Objective-C 中 我们不这样做\N{\fs12}In objective-C we don't do that.
Dialogue: 0,0:31:02.50,0:31:05.22,yin,,0,0,0,,Objective-C 我们有所谓的属性\N{\fs12}In objective-C, we have what's called a property,
Dialogue: 0,0:31:05.24,0:31:09.50,yin,,0,0,0,,属性实际上是一个 setter 方法和一个 getter 方法\N{\fs12}and a property is basically a setter method and a getter method.
Dialogue: 0,0:31:09.50,0:31:12.50,yin,,0,0,0,,所有对实例变量的访问都是如此\N{\fs12}And that's how all access to the instance variable goes,
Dialogue: 0,0:31:12.50,0:31:15.50,yin,,0,0,0,,通过 setter 方法设置值 通过 getter 方法获取值\N{\fs12}through a setter method to set the value and a getter method to get it.
Dialogue: 0,0:31:15.50,0:31:21.15,yin,,0,0,0,,有些人可能很在意性能 会说 我的天\N{\fs12}And some people who maybe are kind of performance junkies might say, oh my gosh,
Dialogue: 0,0:31:21.15,0:31:24.24,yin,,0,0,0,,竟然每一个实例变量都需要调用方法来设置或获取\N{\fs12}every instance variable I have to call a method to set it or get it?
Dialogue: 0,0:31:24.24,0:31:27.50,yin,,0,0,0,,不过记住 这里是为用户界面系统创建的\N{\fs12}But, remember, you're building for a user interface system here,
Dialogue: 0,0:31:27.50,0:31:34.50,yin,,0,0,0,,当用户触到屏幕 这么一点时间内\N{\fs12}when the user touches down, that's taking million, a million code, you know,
Dialogue: 0,0:31:34.50,0:31:38.50,yin,,0,0,0,,就会执行上百万条指令\N{\fs12}you're executing a million instructions there in that amount of time.
Dialogue: 0,0:31:38.50,0:31:41.95,yin,,0,0,0,,多一点 setter 和 getter 方法根本不值得一提\N{\fs12}So, having a few extra setters and getters is completely irrelevant.
Dialogue: 0,0:31:41.96,0:31:44.50,yin,,0,0,0,,这仍然可行\N{\fs12}So it's the old [inaudible] thing, right?
Dialogue: 0,0:31:44.50,0:31:47.50,yin,,0,0,0,,你不需要去优化没有必要优化的事物\N{\fs12}You don't want to optimize things that don't need to be optimized.
Dialogue: 0,0:31:47.50,0:31:50.04,yin,,0,0,0,,你要优化的是很花时间的东西\N{\fs12}You want to optimize the things that are taking a lot of time
Dialogue: 0,0:31:50.04,0:31:53.11,yin,,0,0,0,,而访问实例变量不会花太多时间\N{\fs12}and accessing instance variable turns out not to be taking a lot of your time,
Dialogue: 0,0:31:53.11,0:31:56.13,yin,,0,0,0,,我们来看看这是怎样的\N{\fs12}so, let's look at what it looks like,
Dialogue: 0,0:31:56.13,0:31:59.30,yin,,0,0,0,,不要被这些语法所吓到\N{\fs12}don't get freaked out here by seeing this syntax.
Dialogue: 0,0:31:59.30,0:32:02.50,yin,,0,0,0,,这些都是新的 所以需要花点时间才能习惯\N{\fs12}It's all new, so, it's going to take some getting used to.
Dialogue: 0,0:32:02.50,0:32:05.67,yin,,0,0,0,,在 Objective-C 中 每一个类是这样的\N{\fs12}In objective-C, every class we have
Dialogue: 0,0:32:05.67,0:32:10.50,yin,,0,0,0,,我要展示的类实际上在我将创建的\N{\fs12}and the class I'm going to show you today is a, is in our, essentially our model
Dialogue: 0,0:32:10.50,0:32:13.50,yin,,0,0,0,,纸牌匹配游戏 app 的模型里\N{\fs12}that we're going to build for our card game matching app.
Dialogue: 0,0:32:13.50,0:32:16.50,yin,,0,0,0,,我们会有一个 Card 类和一个 Deck 类\N{\fs12}We're going to have a card and a deck,
Dialogue: 0,0:32:16.50,0:32:19.13,yin,,0,0,0,,我们还有一个 Card 的子类叫 PlayingCard\N{\fs12}and we're also going to have a subclass of card called playing card
Dialogue: 0,0:32:19.13,0:32:21.04,yin,,0,0,0,,还有一个 Deck 的子类叫作 PlayingCardDeck\N{\fs12}and a subclass of deck called playing card deck.
Dialogue: 0,0:32:21.04,0:32:23.91,yin,,0,0,0,,这是我们最开始的模型中的四个类\N{\fs12}Those are the four classes that are going to be in our model, to start.
Dialogue: 0,0:32:23.93,0:32:28.61,yin,,0,0,0,,今天的课上 我将只展示 Card 类\N{\fs12}And, so, I'm going to show you, in today's lecture I'm just going to show you card, only card,
Dialogue: 0,0:32:28.63,0:32:30.35,yin,,0,0,0,,周三我再展示 Deck\N{\fs12}and then on Wednesday I'll show you deck
Dialogue: 0,0:32:30.35,0:32:33.50,yin,,0,0,0,,PlayingCardDeck 和 PlayingCard\N{\fs12}and playing card deck and playing card.
Dialogue: 0,0:32:33.50,0:32:37.87,yin,,0,0,0,,Objective-C 中的每一个类都有一个头文件 如 Card.h\N{\fs12}So, every class in objective-C, you have a header file, card.h,
Dialogue: 0,0:32:37.89,0:32:40.50,yin,,0,0,0,,还有一个实现文件 Card.m\N{\fs12}and you have an implementation file, card.m.
Dialogue: 0,0:32:40.50,0:32:45.09,yin,,0,0,0,,就像 C++ 中你有 .h 和 .c 文件一样\N{\fs12}This is just like in C++ you might have dot h and dot c, or whatever,
Dialogue: 0,0:32:45.09,0:32:49.50,yin,,0,0,0,,这里 .m 我猜 m 表示的是实现 我不知道\N{\fs12}this is dot m, m I guess is for implementation, I don't know.
Dialogue: 0,0:32:49.50,0:32:53.28,yin,,0,0,0,,反正是 m 这些是分开的\N{\fs12}But it's m, and so you have these separate things,
Dialogue: 0,0:32:53.28,0:32:58.04,yin,,0,0,0,,不同之处在于 Card.h 是公共 API\N{\fs12}the difference here is card.h is the public API.
Dialogue: 0,0:32:58.04,0:33:03.02,yin,,0,0,0,,这就是 .h 它是公共 API\N{\fs12}That's what your dot h is. It's your public API.
Dialogue: 0,0:33:03.02,0:33:08.83,yin,,0,0,0,,Card.m 则是私有 API 以及你所有的实现\N{\fs12}Card.m is your private API and all your implementation.
Dialogue: 0,0:33:08.83,0:33:11.81,yin,,0,0,0,,不要把. h 和 .m 搞混\N{\fs12}Don't get confused about dot h and dot m.
Dialogue: 0,0:33:11.81,0:33:14.96,yin,,0,0,0,,.h 是你的公共 API 它就是这个\N{\fs12}All dot h is your public API, that's all it is.
Dialogue: 0,0:33:14.96,0:33:21.04,yin,,0,0,0,,它是类中你希望具有公共性质 让其他人能够调用的方法\N{\fs12}It's what methods in your class you want to make public so that other people can call them.
Dialogue: 0,0:33:21.04,0:33:23.98,yin,,0,0,0,,我们来看看语法是怎样的\N{\fs12}So, let's see what the syntax looks like.
Dialogue: 0,0:33:23.98,0:33:28.50,yin,,0,0,0,,公共 API 中 你必须说明父类是谁\N{\fs12}In your public API, you must say who your superclass is.
Dialogue: 0,0:33:28.50,0:33:33.50,yin,,0,0,0,,你不能够将父类保密\N{\fs12}You are not allowed to make your superclass be a secret.
Dialogue: 0,0:33:33.50,0:33:36.50,yin,,0,0,0,,它需要是公共的 需要放到头文件中\N{\fs12}It has to be public so we have to put it in the header file,
Dialogue: 0,0:33:36.50,0:33:39.50,yin,,0,0,0,,这里是使用的语法 我们使用 @interface\N{\fs12}and you can see the syntax we use is @interface,
Dialogue: 0,0:33:39.50,0:33:40.92,yin,,0,0,0,,然后是类名\N{\fs12}the name of our class,
Dialogue: 0,0:33:40.93,0:33:43.50,yin,,0,0,0,,这必须同文件名一样\N{\fs12}which should always match the name of the file, by the way,
Dialogue: 0,0:33:43.50,0:33:47.11,yin,,0,0,0,,Card.h 应该总是有 Card 类的接口\N{\fs12}card.h should always have the interface for the class card.
Dialogue: 0,0:33:47.11,0:33:49.50,yin,,0,0,0,,然后冒号 后面是父类\N{\fs12}And then a colon and then your superclass.
Dialogue: 0,0:33:49.50,0:33:52.50,yin,,0,0,0,,Card 类的父类是 NSObject\N{\fs12}Now the superclass of the card class is NSObject.
Dialogue: 0,0:33:52.50,0:33:57.11,yin,,0,0,0,,NSObject 在 Foundation 框架中\N{\fs12}NSObject is in the foundation framework
Dialogue: 0,0:33:57.11,0:34:01.54,yin,,0,0,0,,它可以说是 iOS 中每一个类的根类\N{\fs12}and it's pretty much the root class of every single class in all of iOS,
Dialogue: 0,0:34:01.54,0:34:03.50,yin,,0,0,0,,包括你所写的所有类\N{\fs12}including all the classes you write.
Dialogue: 0,0:34:03.50,0:34:07.11,yin,,0,0,0,,这是一种基本的类 我在 Foundation 中会讲到\N{\fs12}It's this kind of basic class, we'll talk about it when we talk about foundation,
Dialogue: 0,0:34:07.11,0:34:10.50,yin,,0,0,0,,总之 它是每一个类的最终父类\N{\fs12}but it's going to be the superclass eventually of every single class.
Dialogue: 0,0:34:10.50,0:34:13.50,yin,,0,0,0,,一切最终都是从 NSObject 继承\N{\fs12}Everything, eventually, inherits from NSObject.
Dialogue: 0,0:34:13.50,0:34:17.50,yin,,0,0,0,,在实现端 情况也很类似\N{\fs12}Now, on the implementation side, it looks very similar,
Dialogue: 0,0:34:17.50,0:34:19.50,yin,,0,0,0,,不过这里不说 @interface\N{\fs12}but instead of saying at sign interface, you say
Dialogue: 0,0:34:19.50,0:34:22.50,yin,,0,0,0,,而说 @implementation 后跟类名\N{\fs12}@implementation and the name of the class.
Dialogue: 0,0:34:22.50,0:34:25.50,yin,,0,0,0,,这里不需要指定父类\N{\fs12}And here you don't specify your superclass.
Dialogue: 0,0:34:25.50,0:34:28.74,yin,,0,0,0,,因为这只需要指定一次 而它是公共的\N{\fs12}Because you're only allowed to specify that once, and it's public,
Dialogue: 0,0:34:28.74,0:34:30.50,yin,,0,0,0,,所以是在头文件中\N{\fs12}so it goes in your header file.
Dialogue: 0,0:34:30.50,0:34:34.50,yin,,0,0,0,,注意到两者的底部都有 @end\N{\fs12}Notice that the bottom of both of these, little at sign end, do you see that?
Dialogue: 0,0:34:34.50,0:34:38.50,yin,,0,0,0,,这里表示的是接口或实现的结束\N{\fs12}Okay, that just means that's the end of the interface or of the implantation.
Dialogue: 0,0:34:38.50,0:34:43.89,yin,,0,0,0,,所有公共 API 都在 @interface 和 @end 之间\N{\fs12}So all of your public API goes inside this at sign interface block, at sign interface,
Dialogue: 0,0:34:43.89,0:34:47.50,yin,,0,0,0,,而所有私有实现都在\N{\fs12}and all of your implementation, your private implementation goes
Dialogue: 0,0:34:47.50,0:34:49.92,yin,,0,0,0,,@implementation 和 @end 之间\N{\fs12}in the at sign implementation part.
Dialogue: 0,0:34:49.94,0:34:56.02,yin,,0,0,0,,要指定父类 你需要导入\N{\fs12}Now, if you import, if you have specified your superclass here, you have to import it.
Dialogue: 0,0:34:56.02,0:34:58.37,yin,,0,0,0,,这就像是 #include 一样\N{\fs12}Which is like pound sign, include.
Dialogue: 0,0:34:58.37,0:35:00.33,yin,,0,0,0,,不过它比 #include 要强大\N{\fs12}It's a little more powerful than pound sign, include,
Dialogue: 0,0:35:00.33,0:35:03.11,yin,,0,0,0,,强大很多 等下我就会讲到\N{\fs12}in fact, it's a lot more powerful, as I'll talk about in a second here.
Dialogue: 0,0:35:03.11,0:35:04.50,yin,,0,0,0,,你必须导入\N{\fs12}But you must import it,
Dialogue: 0,0:35:04.50,0:35:08.11,yin,,0,0,0,,否则 Objective-C 编译器就不知道你的父类是什么\N{\fs12}otherwise the objective-C compiler won't know what that superclass is,
Dialogue: 0,0:35:08.11,0:35:10.24,yin,,0,0,0,,所以你必须导入父类\N{\fs12}so you have to, obviously, import your superclass.
Dialogue: 0,0:35:10.24,0:35:15.00,yin,,0,0,0,,不过 通常对于 iOS 中的父类\N{\fs12}However, we don't usually, when our superclass is something that's in iOS,
Dialogue: 0,0:35:15.02,0:35:19.50,yin,,0,0,0,,我们不会只导入类的头文件 这里是 Foundation\N{\fs12}we don't usually import just that class's header file, which in this case is foundation,
Dialogue: 0,0:35:19.50,0:35:23.50,yin,,0,0,0,,我们会导入整个框架\N{\fs12}we actually import the entire framework.
Dialogue: 0,0:35:23.50,0:35:26.50,yin,,0,0,0,,你也许会说 这太低效了吧\N{\fs12}Now you might say, oh, that's inefficient.
Dialogue: 0,0:35:26.50,0:35:29.15,yin,,0,0,0,,框架得有多大\N{\fs12}A huge framework,
Dialogue: 0,0:35:29.16,0:35:32.50,yin,,0,0,0,,当然 这是已经经过预编译和优化的\N{\fs12}but of course this is all precompiled and optimized.
Dialogue: 0,0:35:32.50,0:35:39.13,yin,,0,0,0,,iOS7 中实际语法是 @import Foundation\N{\fs12}And, in fact, in iOS7, the syntax for this is really to say at sign import foundation.
Dialogue: 0,0:35:39.13,0:35:44.50,yin,,0,0,0,,这意味着我将使用 Foundation 框架中的所有公共类\N{\fs12}That means I'm going to use all the public classes in the foundation framework.
Dialogue: 0,0:35:44.50,0:35:47.24,yin,,0,0,0,,iOS7 仍然支持原来的\N{\fs12}iOS7 still supports the old
Dialogue: 0,0:35:47.24,0:35:49.44,yin,,0,0,0,,import Foundation/Foundation.h\N{\fs12}import foundation slash foundation.h
Dialogue: 0,0:35:49.44,0:35:51.50,yin,,0,0,0,,希望的话 你也可以用这个\N{\fs12}so you can use that if you want.
Dialogue: 0,0:35:51.50,0:35:57.50,yin,,0,0,0,,在实现文件中 我们显然需要导入头文件\N{\fs12}Now on our implementation file, we have to import our header file, obviously.
Dialogue: 0,0:35:57.50,0:35:59.70,yin,,0,0,0,,因为实现文件需要知道\N{\fs12}Because our implementation file needs to know
Dialogue: 0,0:35:59.70,0:36:03.85,yin,,0,0,0,,就 API 而言 我们使用的什么公共 API\N{\fs12}what we're committing to publicly, in terms of our API,
Dialogue: 0,0:36:03.85,0:36:07.05,yin,,0,0,0,,我们需要把这个导入 很好理解\N{\fs12}so we have to import that. Makes perfect sense.
Dialogue: 0,0:36:07.05,0:36:11.50,yin,,0,0,0,,我们还可以有私有声明\N{\fs12}We can also have private declarations.
Dialogue: 0,0:36:11.50,0:36:16.50,yin,,0,0,0,,声明私有的属性和方法\N{\fs12}Declarations of properties and methods that are private
Dialogue: 0,0:36:16.50,0:36:20.13,yin,,0,0,0,,在实现文件内 使用这种 @interface\N{\fs12}inside of our implementation file by putting this little at sign interface,
Dialogue: 0,0:36:20.13,0:36:23.50,yin,,0,0,0,,类名 开闭圆括号\N{\fs12}name of our class, open parentheses, closed parentheses.
Dialogue: 0,0:36:23.50,0:36:25.20,yin,,0,0,0,,@end 结尾\N{\fs12}And then at sign end.
Dialogue: 0,0:36:25.22,0:36:27.87,yin,,0,0,0,,这里我们可以加入私有声明\N{\fs12}So we can have a little space here where we can put little private declarations.
Dialogue: 0,0:36:27.89,0:36:30.50,yin,,0,0,0,,Objective-C 并不要求你\N{\fs12}Now, objective-C does not require you
Dialogue: 0,0:36:30.50,0:36:33.87,yin,,0,0,0,,在实际使用之前进行声明\N{\fs12}to declare something before you use it in a file,
Dialogue: 0,0:36:33.89,0:36:35.29,yin,,0,0,0,,知道我说的什么吗\N{\fs12}you know what I mean by that?
Dialogue: 0,0:36:35.31,0:36:37.50,yin,,0,0,0,,很多语言中\N{\fs12}And there's a lot, a lot of languages,
Dialogue: 0,0:36:37.50,0:36:40.50,yin,,0,0,0,,在调用一个方法前 你需要声明这个函数\N{\fs12}you have to declare a method before you can call it, right?
Dialogue: 0,0:36:40.50,0:36:42.50,yin,,0,0,0,,但 Objective-C 中你可以颠倒过来\N{\fs12}But you can do it out of order in objective-C,
Dialogue: 0,0:36:42.50,0:36:45.00,yin,,0,0,0,,例如你可以实现一个方法 A 调用方法 B\N{\fs12}you can implement a method here that calls,
Dialogue: 0,0:36:45.00,0:36:47.50,yin,,0,0,0,,例如你可以实现一个方法 A 调用方法 B\N{\fs12}you can implement method A, calls method B,
Dialogue: 0,0:36:47.50,0:36:50.50,yin,,0,0,0,,然后方法 B 在文件后面某处才实现\N{\fs12}and then method B is implemented down here later in the file.
Dialogue: 0,0:36:50.50,0:36:52.50,yin,,0,0,0,,你不需要在前面声明方法 B\N{\fs12}So you don't have to declare method B first,
Dialogue: 0,0:36:52.50,0:36:56.50,yin,,0,0,0,,再去实现方法 A 再实现方法 B\N{\fs12}then implement method A, and then implement method B.
Dialogue: 0,0:36:56.50,0:37:01.50,yin,,0,0,0,,这种私有 @interface 主要被用于属性\N{\fs12}So, this little private at sign interface we're mostly going to use for properties.
Dialogue: 0,0:37:01.50,0:37:03.81,yin,,0,0,0,,因为当我们声明属性时\N{\fs12}Okay? Because when we declare a property,
Dialogue: 0,0:37:03.81,0:37:06.50,yin,,0,0,0,,setter 和 getter 会为我们写好\N{\fs12}as you'll see, that setter and getter get written for us.
Dialogue: 0,0:37:06.50,0:37:10.50,yin,,0,0,0,,我们来看看怎么声明属性\N{\fs12}So let's see what that looks like to declare a property.
Dialogue: 0,0:37:10.50,0:37:13.50,yin,,0,0,0,,这里是一个简单属性 叫作 contents\N{\fs12}So here's a simple property. It's called contents.
Dialogue: 0,0:37:13.50,0:37:17.11,yin,,0,0,0,,表示纸牌的内容 纸牌上印有什么\N{\fs12}So this is the content of the card. This is what's on the card.
Dialogue: 0,0:37:17.11,0:37:19.50,yin,,0,0,0,,可以是梅花 A\N{\fs12}So this might be ace of clubs.
Dialogue: 0,0:37:19.50,0:37:23.50,yin,,0,0,0,,由于这是你们第一天上课\N{\fs12}Okay? And because this is your first day,
Dialogue: 0,0:37:23.50,0:37:26.50,yin,,0,0,0,,我们会让内容非常简单 仅仅是一个字符串\N{\fs12}we're going to make the contents be very simple, just a string.
Dialogue: 0,0:37:26.50,0:37:29.50,yin,,0,0,0,,这些纸牌可能是抽认卡\N{\fs12}Okay? So these cards, they can be like a flashcard,
Dialogue: 0,0:37:29.50,0:37:31.50,yin,,0,0,0,,也许是用于学外语用的\N{\fs12}maybe, for learning a foreign language, maybe this is
Dialogue: 0,0:37:31.50,0:37:34.50,yin,,0,0,0,,也许内容是你要学的单词\N{\fs12}the contents are the word that you're trying to learn
Dialogue: 0,0:37:34.50,0:37:36.50,yin,,0,0,0,,也许它是图像抽认卡\N{\fs12}and maybe it's a flashcard of images
Dialogue: 0,0:37:36.50,0:37:40.50,yin,,0,0,0,,内容是图像的名字\N{\fs12}where this content is the name of some image and
Dialogue: 0,0:37:40.50,0:37:43.50,yin,,0,0,0,,交给 UI 来显示匹配的图像\N{\fs12}it's up to UI to display an image that matches it.
Dialogue: 0,0:37:43.50,0:37:45.50,yin,,0,0,0,,在我们的纸牌游戏中\N{\fs12}Or in the case of our playing cards,
Dialogue: 0,0:37:45.50,0:37:48.14,yin,,0,0,0,,我们的内容是字母 A\N{\fs12}we're going to have this be like, literally the character A
Dialogue: 0,0:37:48.14,0:37:49.50,yin,,0,0,0,,及梅花符号\N{\fs12}and then the character clubs,
Dialogue: 0,0:37:49.50,0:37:51.98,yin,,0,0,0,,有一个 Unicode 字符表示梅花\N{\fs12}because there's Unicode character clubs,
Dialogue: 0,0:37:51.98,0:37:54.01,yin,,0,0,0,,梅花 A 这就是内容\N{\fs12}so the A clubs, that would be the content.
Dialogue: 0,0:37:54.05,0:37:56.50,yin,,0,0,0,,这是纸牌内容 纸牌上印有什么\N{\fs12}So this is the content of the card, what's on the card.
Dialogue: 0,0:37:56.50,0:38:00.22,yin,,0,0,0,,这里可以看到有 NSString\N{\fs12}And you can see that it's an NSString star.
Dialogue: 0,0:38:00.22,0:38:02.38,yin,,0,0,0,,前面有 @property\N{\fs12}You see at sign property
Dialogue: 0,0:38:02.38,0:38:06.49,yin,,0,0,0,,这会声明每一个纸牌实例都需要空间\N{\fs12}is how we're going to declare that we need storage, per instance of card,
Dialogue: 0,0:38:06.50,0:38:10.50,yin,,0,0,0,,换言之 每一张纸牌都有自己的内容 contents\N{\fs12}in other words every card has its own contents, and
Dialogue: 0,0:38:10.50,0:38:13.01,yin,,0,0,0,,这是一个字符串 所以我们说\N{\fs12}it's going to be a string, and so we say
Dialogue: 0,0:38:13.01,0:38:15.20,yin,,0,0,0,,property NSString\N{\fs12}property NSString star, now,
Dialogue: 0,0:38:15.20,0:38:19.50,yin,,0,0,0,,在 Objective-C 中理解这个很重要 所有对象\N{\fs12}it's important to understand that in objective-C all objects,
Dialogue: 0,0:38:19.50,0:38:23.50,yin,,0,0,0,,都在堆中 我们有指针指向它们\N{\fs12}all of them, live in the heap and we have pointers to them.
Dialogue: 0,0:38:23.50,0:38:29.50,yin,,0,0,0,,这里没有将对象放到栈上等等这样的情况\N{\fs12}There's no such thing as making an object on the stack or anything like that.
Dialogue: 0,0:38:29.50,0:38:32.50,yin,,0,0,0,,它们都在堆中 大家知道什么是堆吗 有问题吗\N{\fs12}They're all in the heap. Everyone knows what the heap is? Any questions about that?
Dialogue: 0,0:38:32.50,0:38:34.98,yin,,0,0,0,,也就是分配闲置内存的地方\N{\fs12}That's just where you allocate free memory.
Dialogue: 0,0:38:34.99,0:38:36.50,yin,,0,0,0,,所有对象都在那里\N{\fs12}So all objects are there.
Dialogue: 0,0:38:36.50,0:38:38.94,yin,,0,0,0,,Objective-C 很酷的地方在于\N{\fs12}What's' really cool about objective-C is,
Dialogue: 0,0:38:38.96,0:38:43.07,yin,,0,0,0,,Objective-C 会为你管理所有这些存储\N{\fs12}objective-C will manage all that storage for you.
Dialogue: 0,0:38:43.09,0:38:45.98,yin,,0,0,0,,它会进行分配 也会进行释放\N{\fs12}It will allocate for you and free it for you.
Dialogue: 0,0:38:45.99,0:38:49.50,yin,,0,0,0,,它怎么知道何时释放呢\N{\fs12}Now how does it know when to free it?
Dialogue: 0,0:38:49.50,0:38:51.50,yin,,0,0,0,,答案就是这个 strong\N{\fs12}And the answer is this strong thing,
Dialogue: 0,0:38:51.50,0:38:54.50,yin,,0,0,0,,看到 strong 了吗\N{\fs12}you see the word strong there?
Dialogue: 0,0:38:54.50,0:38:57.31,yin,,0,0,0,,属性可以是强的 就像这个这样\N{\fs12}If, your properties can either be strong, like this one,
Dialogue: 0,0:38:57.31,0:38:58.73,yin,,0,0,0,,或者弱的\N{\fs12}or weak,
Dialogue: 0,0:38:58.74,0:39:00.50,yin,,0,0,0,,就两种 强或弱\N{\fs12}two things, strong or weak.
Dialogue: 0,0:39:00.50,0:39:03.05,yin,,0,0,0,,所有指针属性要么强 要么弱\N{\fs12}And all pointer properties have to be strong or weak
Dialogue: 0,0:39:03.05,0:39:06.29,yin,,0,0,0,,因为 Objective-C 需要知道怎么处理内存和堆\N{\fs12}because the objective-C has to know what to do with the memory and the heap.
Dialogue: 0,0:39:06.31,0:39:09.50,yin,,0,0,0,,强表示保持对这个的存储\N{\fs12}Strong means keep the memory for this,
Dialogue: 0,0:39:09.50,0:39:13.18,yin,,0,0,0,,在堆中 保持这个所指的东西\N{\fs12}for the thing this points to, in the heap,
Dialogue: 0,0:39:13.20,0:39:18.16,yin,,0,0,0,,只要我或其他任何人有一个强指针指向它\N{\fs12}as long as I or anyone else has a strong pointer to it.
Dialogue: 0,0:39:18.16,0:39:20.50,yin,,0,0,0,,这被叫作引用计数\N{\fs12}So, this is called reference counting,
Dialogue: 0,0:39:20.50,0:39:22.50,yin,,0,0,0,,这不是垃圾收集 而是引用计数\N{\fs12}it's not garbage collection, it's reference counting.
Dialogue: 0,0:39:22.50,0:39:25.09,yin,,0,0,0,,Objective-C 会追踪\N{\fs12}So the objective-C is going to keep track
Dialogue: 0,0:39:25.09,0:39:28.44,yin,,0,0,0,,每一个指向堆中对象的强指针\N{\fs12}of every single strong pointer to an object in the heap
Dialogue: 0,0:39:28.44,0:39:31.59,yin,,0,0,0,,只要有一个强指针存在\N{\fs12}and as long as at least one strong pointer exists,
Dialogue: 0,0:39:31.59,0:39:33.22,yin,,0,0,0,,它就会把其留在堆中\N{\fs12}it's going to keep that thing in heap.
Dialogue: 0,0:39:33.22,0:39:35.50,yin,,0,0,0,,只有不再存在任何强指针时\N{\fs12}As soon as there are no strong pointers left,
Dialogue: 0,0:39:35.50,0:39:37.86,yin,,0,0,0,,它才会从堆中释放内存 立刻释放\N{\fs12}it will free the memory out of the heap, instantly.
Dialogue: 0,0:39:37.88,0:39:39.50,yin,,0,0,0,,不是之后的垃圾收集\N{\fs12}Not garbage collected later.
Dialogue: 0,0:39:39.50,0:39:43.14,yin,,0,0,0,,而立刻释放内存\N{\fs12}But actually instantly, reclaim that memory.
Dialogue: 0,0:39:43.20,0:39:45.50,yin,,0,0,0,,这对你们而言可能是新东西\N{\fs12}So this is probably new to you, you're
Dialogue: 0,0:39:45.50,0:39:48.50,yin,,0,0,0,,你们可能习惯了 Java 中的垃圾收集\N{\fs12}probably used to like garbage collection in Java, for example,
Dialogue: 0,0:39:48.50,0:39:52.50,yin,,0,0,0,,或其它语言中的显式内存管理\N{\fs12}or explicit memory management in other languages.
Dialogue: 0,0:39:52.50,0:39:55.14,yin,,0,0,0,,这个叫作自动引用计数 它非常棒\N{\fs12}This is called automatic reference counting and it's awesome.
Dialogue: 0,0:39:55.14,0:39:58.50,yin,,0,0,0,,可预见性很强 比垃圾收集要好很多\N{\fs12}It's really very predictable, this is much better than garbage collection,
Dialogue: 0,0:39:58.50,0:40:01.50,yin,,0,0,0,,因为垃圾收集器会在之后过来\N{\fs12}because, you know, the garbage collector can come along later and
Dialogue: 0,0:40:01.50,0:40:04.05,yin,,0,0,0,,在从堆中收集垃圾时\N{\fs12}do, wreak havoc on the performance of your application
Dialogue: 0,0:40:04.05,0:40:06.27,yin,,0,0,0,,对应用性能会造成严重影响\N{\fs12}as it goes and collects things from the heap.
Dialogue: 0,0:40:06.27,0:40:09.16,yin,,0,0,0,,这个可预见性很强 你知道什么时候内存会释放\N{\fs12}This is very predictable, you know exactly when things are going to be released,
Dialogue: 0,0:40:09.16,0:40:11.50,yin,,0,0,0,,也就是不再有强指针存在时\N{\fs12}it's when there's no strong pointers left to it.
Dialogue: 0,0:40:11.50,0:40:13.27,yin,,0,0,0,,如果是弱呢\N{\fs12}What would it mean if this was weak?
Dialogue: 0,0:40:13.27,0:40:16.12,yin,,0,0,0,,弱指针会告诉 Objective-C\N{\fs12}Okay, if you have a weak pointer, that tells objective-C,
Dialogue: 0,0:40:16.14,0:40:18.50,yin,,0,0,0,,我有一个指针指向堆中的这个\N{\fs12}okay, I have a pointer to this thing in the heap and
Dialogue: 0,0:40:18.50,0:40:22.29,yin,,0,0,0,,只要还有强指针指向它 就将它留在内存中\N{\fs12}keep it in memory as long as someone else has a strong pointer to it.
Dialogue: 0,0:40:22.29,0:40:26.45,yin,,0,0,0,,只要不再有强指针指向它 内存就会释放\N{\fs12}But as soon as no one else has a strong pointer to that thing, it gets freed from memory
Dialogue: 0,0:40:26.46,0:40:30.16,yin,,0,0,0,,此时这个弱指针 会被设置为 nil\N{\fs12}and this pointer, if it was weak, gets set to nil.
Dialogue: 0,0:40:30.16,0:40:33.50,yin,,0,0,0,,nil 表示 这个指针不指向任何东西\N{\fs12}Nil means this pointer doesn't point to anything.
Dialogue: 0,0:40:33.50,0:40:36.50,yin,,0,0,0,,nil 也就是零\N{\fs12}Nil is the same as zero.
Dialogue: 0,0:40:36.50,0:40:40.96,yin,,0,0,0,,在其它语言中 你们可能会害怕 nil 指针\N{\fs12}In other languages, you're probably afraid of nil pointers.
Dialogue: 0,0:40:40.97,0:40:45.50,yin,,0,0,0,,因为引用 nil 指针会让你的程序崩溃\N{\fs12}Because you do reference a nil pointer, it crashes your program, right?
Dialogue: 0,0:40:45.50,0:40:49.50,yin,,0,0,0,,在 Objective-C 中 你可以发送消息给 nil 指针\N{\fs12}In objective-C, you can send messages to nil pointers even
Dialogue: 0,0:40:49.50,0:40:51.58,yin,,0,0,0,,这不会让你的程序崩溃掉\N{\fs12}and it will not crash your program.
Dialogue: 0,0:40:51.59,0:40:55.92,yin,,0,0,0,,实际上 如果你将消息发送给 nil 指针\N{\fs12}In fact, if you send a message to a nil pointer,
Dialogue: 0,0:40:55.92,0:40:58.23,yin,,0,0,0,,它显然不会执行任何代码\N{\fs12}it will not execute any code, obviously,
Dialogue: 0,0:40:58.23,0:41:00.50,yin,,0,0,0,,因为这里没有实例\N{\fs12}because there's no instance there.
Dialogue: 0,0:41:00.50,0:41:02.32,yin,,0,0,0,,而且它会返回 0\N{\fs12}And it will return zero from,
Dialogue: 0,0:41:02.33,0:41:05.50,yin,,0,0,0,,如果那个消息有返回值 它会返回 0\N{\fs12}if that message had a return value, it'll return zero.
Dialogue: 0,0:41:05.50,0:41:09.50,yin,,0,0,0,,你需要小心返回 struct 类型的消息\N{\fs12}So you have to be a little careful of messages that return structs,
Dialogue: 0,0:41:09.50,0:41:12.50,yin,,0,0,0,,但只要它返回的是原始类型或指针\N{\fs12}but as long as it returns a primitive type or a pointer,
Dialogue: 0,0:41:12.50,0:41:13.99,yin,,0,0,0,,它会返回 0\N{\fs12}it'll just return zero.
Dialogue: 0,0:41:14.01,0:41:16.50,yin,,0,0,0,,这需要时间才能习惯\N{\fs12}So, this is going to take getting used to.
Dialogue: 0,0:41:16.50,0:41:18.50,yin,,0,0,0,,我们在编程过程中\N{\fs12}The fact that we are going to program
Dialogue: 0,0:41:18.50,0:41:23.50,yin,,0,0,0,,知道能发消息给 nil 指针 这是有好处的\N{\fs12}knowing that we can send messages to nil, to pointers that are nil and that that's good.
Dialogue: 0,0:41:23.50,0:41:27.94,yin,,0,0,0,,我们会利用这个让代码工作得更好\N{\fs12}We'll actually make our code work nicely and we'll use that to our advantage.
Dialogue: 0,0:41:27.96,0:41:30.16,yin,,0,0,0,,这对于你们来说是个改变\N{\fs12}And that is definitely going to be a change for you
Dialogue: 0,0:41:30.16,0:41:31.25,yin,,0,0,0,,你们原来都习惯\N{\fs12}who are used to
Dialogue: 0,0:41:31.25,0:41:34.40,yin,,0,0,0,,如果指针非 nil 那么发送消息这些\N{\fs12}if pointers not nil, then send message all the time, right?
Dialogue: 0,0:41:34.40,0:41:35.88,yin,,0,0,0,,以此来防止崩溃\N{\fs12}Protecting against crashes,
Dialogue: 0,0:41:35.88,0:41:39.50,yin,,0,0,0,,Objective-C 中不需要这样编写代码\N{\fs12}you don't do that in objective-C, you just don't code it that way.
Dialogue: 0,0:41:39.50,0:41:44.18,yin,,0,0,0,,这个指针可以有值 nil\N{\fs12}So, this pointer could have the value nil, n-i-l,
Dialogue: 0,0:41:44.18,0:41:46.50,yin,,0,0,0,,也就是说它不指向任何东西\N{\fs12}which means it doesn't point to anything.
Dialogue: 0,0:41:46.50,0:41:49.31,yin,,0,0,0,,如果你有一个强指针 它指向什么东西\N{\fs12}So if you have a strong pointer and it points to something
Dialogue: 0,0:41:49.31,0:41:50.73,yin,,0,0,0,,然后你把它设为 nil\N{\fs12}and then you set it to nil,
Dialogue: 0,0:41:50.75,0:41:52.68,yin,,0,0,0,,那个强指针不再指向那个东西\N{\fs12}now that strong pointer doesn't point to that thing,
Dialogue: 0,0:41:52.68,0:41:54.14,yin,,0,0,0,,只要没有其它指针指向它\N{\fs12}as long as no one else points to it,
Dialogue: 0,0:41:54.14,0:41:57.50,yin,,0,0,0,,你就能够释放这里的内存 Objective-C 会帮你释放内存\N{\fs12}you can clean up that memory, objective-C will clean the memory up for you.
Dialogue: 0,0:41:57.50,0:41:59.50,yin,,0,0,0,,或者 如果你有一个指针指向堆中某东西\N{\fs12}Or if you have a pointer that points to something in the heap,
Dialogue: 0,0:41:59.50,0:42:01.50,yin,,0,0,0,,你让它指向堆中别的东西\N{\fs12}then you make it point to something else in the heap,
Dialogue: 0,0:42:01.50,0:42:04.50,yin,,0,0,0,,然后不再有强指针指向原来那个东西\N{\fs12}then you no longer have a strong pointer to that other thing
Dialogue: 0,0:42:04.50,0:42:07.50,yin,,0,0,0,,只要不再有强指针如此 内存就会释放\N{\fs12}in the heap and as long as no one does, it'll get cleaned up.
Dialogue: 0,0:42:07.50,0:42:10.50,yin,,0,0,0,,记住 弱的情况 不仅是释放\N{\fs12}And remember weak not only cleans it up,
Dialogue: 0,0:42:10.50,0:42:12.18,yin,,0,0,0,,指针还会被设为 nil\N{\fs12}but it sets your pointer to nil,
Dialogue: 0,0:42:12.18,0:42:13.86,yin,,0,0,0,,因为你只想要一个弱指针\N{\fs12}because you only wanted a weak pointer,
Dialogue: 0,0:42:13.86,0:42:16.50,yin,,0,0,0,,你只希望有强指针指向对象时它才指向对象\N{\fs12}you only wanted it to point to that thing as long as someone else does.
Dialogue: 0,0:42:16.50,0:42:19.50,yin,,0,0,0,,这就是强和弱\N{\fs12}So that's the strong versus weak.
Dialogue: 0,0:42:19.50,0:42:24.12,yin,,0,0,0,,括号里我们还要加一个 nonatomic(非原子)\N{\fs12}The other thing we're going to put in this little parentheses is nonatomic.
Dialogue: 0,0:42:24.12,0:42:29.53,yin,,0,0,0,,非原子是说同该属性一同的 setter 和 getter\N{\fs12}Nonatomic means calling this setter and getter that go along with this property
Dialogue: 0,0:42:29.53,0:42:31.50,yin,,0,0,0,,不是线程安全的\N{\fs12}is not thread safe.
Dialogue: 0,0:42:31.50,0:42:36.14,yin,,0,0,0,,你不能有两个线程 同时尝试设置该属性\N{\fs12}So you can't have two threads trying to set this property at the same time.
Dialogue: 0,0:42:36.14,0:42:39.50,yin,,0,0,0,,为什么这里要非原子呢 为什么不能是线程安全的呢\N{\fs12}Why do we say nonatomic here, why do we want this to not be thread safe?
Dialogue: 0,0:42:39.50,0:42:42.93,yin,,0,0,0,,因为 iOS 中的多线程\N{\fs12}Because the way we do multithreading in iOS
Dialogue: 0,0:42:42.94,0:42:46.14,yin,,0,0,0,,不是一个对象上多个线程在设置\N{\fs12}is not by having a single object that multiple threads are setting on,
Dialogue: 0,0:42:46.14,0:42:49.27,yin,,0,0,0,,我们通常有另外一组对象 运行在另外一个线程\N{\fs12}we usually have a separate set of objects that are running in another thread,
Dialogue: 0,0:42:49.27,0:42:51.03,yin,,0,0,0,,例如你的模型\N{\fs12}like your model,
Dialogue: 0,0:42:51.03,0:42:54.50,yin,,0,0,0,,然后 UI 这些东西运行在 UI 线程\N{\fs12}and then other, then your UI stuff is running in the UI thread
Dialogue: 0,0:42:54.50,0:42:57.03,yin,,0,0,0,,它们在线程间进行通信\N{\fs12}and they're talking thread to thread.
Dialogue: 0,0:42:57.05,0:43:00.50,yin,,0,0,0,,所以我们不需要这个 不仅如此\N{\fs12}So we don't need this and not only that,
Dialogue: 0,0:43:00.50,0:43:03.25,yin,,0,0,0,,这里使用 @property 时\N{\fs12}what's going to happen here when we do this at sign property
Dialogue: 0,0:43:03.25,0:43:06.50,yin,,0,0,0,,Objective-C 会创建我讲过的 getter 和 setter 方法\N{\fs12}is objective-C is going to create that getter and setter methods that I told
Dialogue: 0,0:43:06.50,0:43:09.50,yin,,0,0,0,,来自动为我们设置 contents\N{\fs12}you about to set these contents automatically for us,
Dialogue: 0,0:43:09.50,0:43:12.50,yin,,0,0,0,,而我们希望它们很简单\N{\fs12}and we want them to be simple.
Dialogue: 0,0:43:12.50,0:43:14.50,yin,,0,0,0,,它们是这样的\N{\fs12}This is what they're going to look like.
Dialogue: 0,0:43:14.50,0:43:16.50,yin,,0,0,0,,我们希望它们很简单\N{\fs12}We want them to be simple.
Dialogue: 0,0:43:16.50,0:43:20.21,yin,,0,0,0,,如果我们不说 nonatomic 这里会有各种锁定代码\N{\fs12}If we don't say nonatomic, there's going to be all kinds of locking code in there, right?
Dialogue: 0,0:43:20.21,0:43:22.36,yin,,0,0,0,,如果你有多线程\N{\fs12}If you have multiple threads and you're
Dialogue: 0,0:43:22.36,0:43:26.01,yin,,0,0,0,,你允许多线程访问这里的 setter 和 getter\N{\fs12}allowing multiple threads to access the setter and getter here,
Dialogue: 0,0:43:26.03,0:43:28.50,yin,,0,0,0,,那你就需要锁定代码 我们不想要锁定代码\N{\fs12}then you need locking code, and we don't want locking code,
Dialogue: 0,0:43:28.50,0:43:31.82,yin,,0,0,0,,尤其是我们要自己实现 setter 和 getter 时\N{\fs12}especially if we're going to implement the setter and getter ourselves,
Dialogue: 0,0:43:31.82,0:43:34.50,yin,,0,0,0,,有时我们确实会这样做\N{\fs12}which we're going to, sometimes.
Dialogue: 0,0:43:34.50,0:43:38.50,yin,,0,0,0,,不过默认情况下 我们不用实现 setter 和 getter\N{\fs12}But the default here is that we don't implement this setter and getter,
Dialogue: 0,0:43:38.50,0:43:40.50,yin,,0,0,0,,它会自动为我们实现\N{\fs12}it's automatically in there for us.
Dialogue: 0,0:43:40.50,0:43:42.50,yin,,0,0,0,,可以看到这里的三部分\N{\fs12}So you can see there's three parts to this.
Dialogue: 0,0:43:42.50,0:43:45.03,yin,,0,0,0,,这里有 @synthesize(合成) 看到了吗\N{\fs12}There's the at sign synthesize, you see that?
Dialogue: 0,0:43:45.05,0:43:50.50,yin,,0,0,0,,这里 _contents 是实例变量的名字\N{\fs12}That's basically just saying underbar contents is the name of the instance variable
Dialogue: 0,0:43:50.50,0:43:53.50,yin,,0,0,0,,属性 contents 将存储于此\N{\fs12}in which the property contents is going to be stored.
Dialogue: 0,0:43:53.50,0:43:57.21,yin,,0,0,0,,我们也可以说 @synthesize contents = foo\N{\fs12}Now we could say at sign synthesize contents equals foo,
Dialogue: 0,0:43:57.21,0:44:00.50,yin,,0,0,0,,然后 contents 属性会被存在这个实例变量 foo中\N{\fs12}and then contents property would be stored in an instance variable called foo.
Dialogue: 0,0:44:00.50,0:44:02.21,yin,,0,0,0,,但这很让人犯迷糊\N{\fs12}But that would be very confusing,
Dialogue: 0,0:44:02.21,0:44:05.50,yin,,0,0,0,,所以我们总是使用下划线属性名\N{\fs12}so we always use underbar name of the property.
Dialogue: 0,0:44:05.50,0:44:07.66,yin,,0,0,0,,这是第一部分\N{\fs12}And so that's part one,
Dialogue: 0,0:44:07.66,0:44:12.50,yin,,0,0,0,,只是分配实例变量来存储 contents 属性\N{\fs12}just basically allocating an instance variable to store this contents property.
Dialogue: 0,0:44:12.50,0:44:14.06,yin,,0,0,0,,然后是 getter\N{\fs12}Then there's the getter,
Dialogue: 0,0:44:14.06,0:44:15.97,yin,,0,0,0,,也就是 (NSString *)contents\N{\fs12}that's NSString contents,
Dialogue: 0,0:44:15.97,0:44:17.27,yin,,0,0,0,,return _contents\N{\fs12}return contents,
Dialogue: 0,0:44:17.27,0:44:20.43,yin,,0,0,0,,- (NSString *)contents\N{\fs12}so the dash, parentheses, NSString contents
Dialogue: 0,0:44:20.43,0:44:23.50,yin,,0,0,0,,是 Objective-C 中的一个方法声明\N{\fs12}is a method declaration in objective-C,
Dialogue: 0,0:44:23.50,0:44:25.50,yin,,0,0,0,,- 表示这是一个方法\N{\fs12}the dash means this is a method,
Dialogue: 0,0:44:25.50,0:44:27.40,yin,,0,0,0,,(NSString *) 表示\N{\fs12}parentheses NSString star means
Dialogue: 0,0:44:27.40,0:44:30.50,yin,,0,0,0,,这一方法返回指向字符串的指针\N{\fs12}this is a method that returns a pointer to a string,
Dialogue: 0,0:44:30.50,0:44:33.50,yin,,0,0,0,,contents 则是方法名\N{\fs12}and contents is the name of the method.
Dialogue: 0,0:44:33.50,0:44:37.50,yin,,0,0,0,,getter 的方法名同属性名一样\N{\fs12}So the name of the method of the getter is the same as the name of the property.
Dialogue: 0,0:44:37.50,0:44:43.50,yin,,0,0,0,,然后 实现就是返回我们所合成的实例变量\N{\fs12}Then, the implementation is just return that instance variable that we synthesized.
Dialogue: 0,0:44:43.50,0:44:49.17,yin,,0,0,0,,类似地 下一个方法是 Objective-C 中设置的方法\N{\fs12}And similarly, the next method is a method in objective-C for setting it.
Dialogue: 0,0:44:49.17,0:44:51.50,yin,,0,0,0,,还是一样 - 表示这是一个方法\N{\fs12}And, again, dash because this is a method.
Dialogue: 0,0:44:51.50,0:44:55.50,yin,,0,0,0,,(void) 表示这个方法不返回任何东西\N{\fs12}Parentheses void means this method does not return anything.
Dialogue: 0,0:44:55.50,0:44:57.50,yin,,0,0,0,,(void) 就是这个意思\N{\fs12}That's what parentheses void means.
Dialogue: 0,0:44:57.50,0:45:00.88,yin,,0,0,0,,然后 setContents: 这是该方法的名\N{\fs12}Then set contents colon, that's the name of this method,
Dialogue: 0,0:45:00.88,0:45:03.08,yin,,0,0,0,,意思是设置内容\N{\fs12}set contents colon.
Dialogue: 0,0:45:03.08,0:45:07.50,yin,,0,0,0,,(NSString *) 是该方法的参数\N{\fs12}Parentheses NSString star is the argument to this method.
Dialogue: 0,0:45:07.50,0:45:10.91,yin,,0,0,0,,contents 则是参数名\N{\fs12}Contents is just the name of the argument, the local name of the
Dialogue: 0,0:45:10.91,0:45:14.23,yin,,0,0,0,,局部环境下变量的局部名\N{\fs12}variable in the local contents, context,
Dialogue: 0,0:45:14.23,0:45:17.21,yin,,0,0,0,,实现是 _contents\N{\fs12}and the implementation is just underbar contents,
Dialogue: 0,0:45:17.21,0:45:20.50,yin,,0,0,0,,我们的实例变量 = 那个参数\N{\fs12}our instance variable equals that argument.
Dialogue: 0,0:45:20.50,0:45:25.64,yin,,0,0,0,,在我继续推进之前 大家是否都理解了这两个方法\N{\fs12}So, before I move on, does everyone understand how these two methods
Dialogue: 0,0:45:25.64,0:45:33.50,yin,,0,0,0,,它们让你能够在 Card 内设置和获取 NSString 存储空间\N{\fs12}are allowing you to set and get an NSString storage space inside your card?
Dialogue: 0,0:45:33.50,0:45:35.50,yin,,0,0,0,,大家都明白这个了吗\N{\fs12}Everyone understand that?
Dialogue: 0,0:45:35.50,0:45:36.78,yin,,0,0,0,,有问题\N{\fs12}Question?
Dialogue: 0,0:45:38.50,0:45:41.06,yin,,0,0,0,,好 synthesize 这一行\N{\fs12}Okay, so the synthesize line, again,
Dialogue: 0,0:45:41.06,0:45:44.30,yin,,0,0,0,,只是指定实例变量名\N{\fs12}is just specifying the name of the instance variable
Dialogue: 0,0:45:44.30,0:45:47.50,yin,,0,0,0,,用以存储这个 _contents\N{\fs12}that we're going to use to store this stuff in, underbar contents.
Dialogue: 0,0:45:47.50,0:45:50.99,yin,,0,0,0,,这有些奇怪 也许更好的说法是\N{\fs12}It's kind of weird, you could maybe, it might be better saying
Dialogue: 0,0:45:50.99,0:45:53.38,yin,,0,0,0,,@synthesize contents\N{\fs12}at sign synthesize contents
Dialogue: 0,0:45:53.38,0:45:56.50,yin,,0,0,0,,去使用名为 _contents 的实例变量\N{\fs12}to use instance variable with name, underbar contents.
Dialogue: 0,0:45:56.50,0:45:58.26,yin,,0,0,0,,我知道 这个等号有点奇怪\N{\fs12}That equals, I know, is a little weird.
Dialogue: 0,0:45:58.27,0:46:03.08,yin,,0,0,0,,看起来就像赋值语句 不过你们可以把这个等号看成\N{\fs12}It sounds like it's assigning something, but it's just, that's what, think about equals as,
Dialogue: 0,0:46:03.08,0:46:07.08,yin,,0,0,0,,使用名为 _contents 的实例变量\N{\fs12}you know, we'll use the instance variable with the name, underbar contents.
Dialogue: 0,0:46:07.10,0:46:08.50,yin,,0,0,0,,这就是 synthesize\N{\fs12}So that's what the synthesize is doing.
Dialogue: 0,0:46:08.50,0:46:12.86,yin,,0,0,0,,没有 synthesize 你将无法为 Card 实例创建空间\N{\fs12}If you don't put the synthesize, it's not going to create the space in your card instance,
Dialogue: 0,0:46:12.86,0:46:17.50,yin,,0,0,0,,而且它没有名 你无法在 getter 和 setter 中引用它\N{\fs12}and there won't be any name for it so you can't refer to it in your getter and setter.
Dialogue: 0,0:46:17.50,0:46:19.50,yin,,0,0,0,,大家都懂了吗\N{\fs12}Everyone understand this?
Dialogue: 0,0:46:19.50,0:46:21.30,yin,,0,0,0,,还有问题吗\N{\fs12}Any other questions?
Dialogue: 0,0:46:21.30,0:46:26.06,yin,,0,0,0,,好 当你在左侧键入 @property 时\N{\fs12}Okay, now, the thing about it is, when you type the at sign property on the left,
Dialogue: 0,0:46:26.06,0:46:28.45,yin,,0,0,0,,这会添加到你的 @implementation\N{\fs12}this gets added to your at sign implementation;
Dialogue: 0,0:46:28.45,0:46:31.50,yin,,0,0,0,,但是 你不会在那里看到它\N{\fs12}however, you will not see it there.
Dialogue: 0,0:46:32.23,0:46:34.50,yin,,0,0,0,,它在那里 但你看不到\N{\fs12}So it's there, but you don't see it.
Dialogue: 0,0:46:34.50,0:46:38.91,yin,,0,0,0,,Objective-C 为你做了那些 但它不会显示出来\N{\fs12}Okay, objective-C is, made it for you, but it doesn't show it to you,
Dialogue: 0,0:46:38.93,0:46:44.23,yin,,0,0,0,,不过它在那里 setter 和 getter 方法都在那里\N{\fs12}but it's there, okay, that setter method and that getter method are there.
Dialogue: 0,0:46:44.23,0:46:45.30,yin,,0,0,0,,它们存在\N{\fs12}They exist.
Dialogue: 0,0:46:45.30,0:46:47.50,yin,,0,0,0,,不仅这样 它们还是公共的\N{\fs12}And not only that, they're public,
Dialogue: 0,0:46:47.50,0:46:51.50,yin,,0,0,0,,因为你在头文件中用了 @property 声明\N{\fs12}because you put that at sign property declaration in your header file.
Dialogue: 0,0:46:51.50,0:46:53.50,yin,,0,0,0,,都明白吗\N{\fs12}Everyone got that?
Dialogue: 0,0:46:53.50,0:46:56.50,yin,,0,0,0,,我们再来看另一个属性 以此进一步熟悉语法\N{\fs12}So let's look at another couple properties just to see the syntax a little more.
Dialogue: 0,0:46:56.50,0:46:59.50,yin,,0,0,0,,这里有两个属性 它们是布尔型的\N{\fs12}So here's two properties that are Boolean.
Dialogue: 0,0:46:59.50,0:47:02.50,yin,,0,0,0,,C 中没有布尔原始类型\N{\fs12}There's no Boolean primitive in C,
Dialogue: 0,0:47:02.50,0:47:06.50,yin,,0,0,0,,所以 Objective-C 使用类型定义全大写的 BOOL\N{\fs12}so objective-C has to find, typedef all caps BOOL,
Dialogue: 0,0:47:06.50,0:47:09.50,yin,,0,0,0,,也许是一个短整型 或整型 或字符型\N{\fs12}probably a short or something or an int or a char,
Dialogue: 0,0:47:09.50,0:47:12.50,yin,,0,0,0,,我不知道具体是什么 不过你可以把它当作原始类型\N{\fs12}I don't know what, but you can think of it as a primitive type,
Dialogue: 0,0:47:12.50,0:47:15.50,yin,,0,0,0,,布尔型的值可以是真\N{\fs12}it's a Boolean, it's value can either be yes,
Dialogue: 0,0:47:15.50,0:47:18.50,yin,,0,0,0,,用某非 0 值表示 也可以是非 用 0 表示\N{\fs12}which is some non-zero value, or no which is zero.
Dialogue: 0,0:47:18.50,0:47:21.50,yin,,0,0,0,,这些属性不需要强或弱来修饰\N{\fs12}And these properties don't need the strong or weak.
Dialogue: 0,0:47:22.17,0:47:24.26,yin,,0,0,0,,能理解为什么吗\N{\fs12}Do you understand why that is?
Dialogue: 0,0:47:24.26,0:47:25.50,yin,,0,0,0,,因为它们是原始类型\N{\fs12}Because they're primitive types,
Dialogue: 0,0:47:25.50,0:47:27.50,yin,,0,0,0,,它们没有存储在堆中\N{\fs12}they're not stored in the heap.
Dialogue: 0,0:47:27.50,0:47:31.06,yin,,0,0,0,,这里只是整型或浮点型 没有内存需要管理\N{\fs12}They're just a int or a float, so there's no memory to manage
Dialogue: 0,0:47:31.08,0:47:34.26,yin,,0,0,0,,所以不需要强或弱指针 这里不涉及到指针\N{\fs12}so you don't need to know about strong and weak pointers, there's no pointers involved here,
Dialogue: 0,0:47:34.26,0:47:35.99,yin,,0,0,0,,只是 BOOL 布尔型\N{\fs12}this is just a BOOL, a Boolean.
Dialogue: 0,0:47:36.00,0:47:39.06,yin,,0,0,0,,所以没有强或弱 但这里仍然有非原子性\N{\fs12}So there's no strong or weak, but we still have the nonatomic,
Dialogue: 0,0:47:39.08,0:47:41.50,yin,,0,0,0,,因为我们仍然希望 setter 和 getter 简单\N{\fs12}because we still want the setter and the getter to be simple,
Dialogue: 0,0:47:41.50,0:47:43.10,yin,,0,0,0,,没有锁定代码这些\N{\fs12}not having any locking code or any of that business.
Dialogue: 0,0:47:43.12,0:47:46.89,yin,,0,0,0,,这个类中的每一种属性我们都用非原子性来修饰\N{\fs12}So we're always going to have nonatomic on every property in this class.
Dialogue: 0,0:47:46.91,0:47:50.04,yin,,0,0,0,,这个类中没有任何一个属性不是非原子的\N{\fs12}We will not have a single property in this entire class that is not nonatomic.
Dialogue: 0,0:47:50.06,0:47:52.43,yin,,0,0,0,,这里写下它 我希望它是默认的\N{\fs12}So just put it in there, I wish it were the default.
Dialogue: 0,0:47:52.45,0:47:54.50,yin,,0,0,0,,这就是我们这里的做法\N{\fs12}So that's what we're going to do.
Dialogue: 0,0:47:54.50,0:47:57.50,yin,,0,0,0,,可以看到这里两者都会合成\N{\fs12}You can see we've synthesized them both
Dialogue: 0,0:47:57.50,0:47:59.50,yin,,0,0,0,,两者都能得到 setter 和 getter\N{\fs12}and we've got the setter and the getter for them both,
Dialogue: 0,0:47:59.50,0:48:02.50,yin,,0,0,0,,这些都由 Objective-C 为我们自动完成\N{\fs12}and this is all being done for us by objective-C.
Dialogue: 0,0:48:02.50,0:48:04.91,yin,,0,0,0,,这里有一点很酷\N{\fs12}Now, one thing that's kind of cool is
Dialogue: 0,0:48:04.91,0:48:07.23,yin,,0,0,0,,我们并不一定喜欢 getter 的名字\N{\fs12}we may not like the name of this getter,
Dialogue: 0,0:48:07.23,0:48:12.87,yin,,0,0,0,,因为我们希望 当纸牌被选择时 做点什么\N{\fs12}because we want our code to read something like if card is chosen, then do something.
Dialogue: 0,0:48:12.89,0:48:14.91,yin,,0,0,0,,如果纸牌匹配时 做点什么\N{\fs12}If card is matched, then do something.
Dialogue: 0,0:48:14.91,0:48:18.50,yin,,0,0,0,,所以我们更愿意 getter 叫 isChosen 而不是只是 chosen\N{\fs12}So we really want the getter called is chosen, not just chosen.
Dialogue: 0,0:48:18.50,0:48:22.50,yin,,0,0,0,,isChosen 强调纸牌是否「是」被选择\N{\fs12}You know, if card chosen, not as nice as if card is chosen.
Dialogue: 0,0:48:22.50,0:48:25.50,yin,,0,0,0,,我们可以为 getter 重命名\N{\fs12}So it's actually possible to rename the getter
Dialogue: 0,0:48:25.50,0:48:29.10,yin,,0,0,0,,只需要在这里加上 getter = 你想要的新名字\N{\fs12}by saying getter equals the new name you want.
Dialogue: 0,0:48:29.10,0:48:31.50,yin,,0,0,0,,这就是重命名\N{\fs12}And that's essentially renamed it,
Dialogue: 0,0:48:31.50,0:48:34.50,yin,,0,0,0,,下面这个也一样 重命名 getter = isMatched\N{\fs12}same thing, we'll do the same thing with this one. Getter equals is matched,
Dialogue: 0,0:48:34.50,0:48:37.17,yin,,0,0,0,,这时 getter 就叫 isMatched 了\N{\fs12}now that getter is called is matched.
Dialogue: 0,0:48:37.19,0:48:38.65,yin,,0,0,0,,我讲这个是想告诉你们\N{\fs12}And I bring this up because you're going to see
Dialogue: 0,0:48:38.65,0:48:40.50,yin,,0,0,0,,iOS 如何像这样处理布尔型属性\N{\fs12}how iOS does this with Boolean properties,
Dialogue: 0,0:48:40.50,0:48:43.87,yin,,0,0,0,,它会重命名它们为「是」这个 或「有」这个\N{\fs12}it tends to rename them to is this or has this,
Dialogue: 0,0:48:43.87,0:48:46.50,yin,,0,0,0,,取决于动词是什么\N{\fs12}depending on what the verb there is.
Dialogue: 0,0:48:46.50,0:48:51.76,yin,,0,0,0,,还是一样 Objective-C 会把所有这些代码写到实现中\N{\fs12}And again, objective-C is writing all this code on, in the implementation,
Dialogue: 0,0:48:51.78,0:48:53.50,yin,,0,0,0,,但你看不到\N{\fs12}but you don't see it.
Dialogue: 0,0:48:53.50,0:48:55.50,yin,,0,0,0,,不过它在那里\N{\fs12}But it's there.
Dialogue: 0,0:48:55.50,0:49:00.19,yin,,0,0,0,,以后的课上我会讲到为什么说属性很好\N{\fs12}Now, we're going to talk about why properties are good
Dialogue: 0,0:49:00.19,0:49:05.54,yin,,0,0,0,,为什么说它比直接访问实例变量要好\N{\fs12}and why it's better than just accessing instance variables directly, in later lectures,
Dialogue: 0,0:49:05.56,0:49:09.50,yin,,0,0,0,,总的来说 它便于平衡检验\N{\fs12}but the bottom-line is it's good for doing things like balance checking,
Dialogue: 0,0:49:09.50,0:49:13.50,yin,,0,0,0,,便于你设置属性后更新 UI\N{\fs12}it's good for doing things like when you set a property and you want to updated the UI.
Dialogue: 0,0:49:13.50,0:49:16.50,yin,,0,0,0,,便于初始化指针\N{\fs12}It's doing good for things for initializing pointers.
Dialogue: 0,0:49:16.50,0:49:21.24,yin,,0,0,0,,比如 NSString *contents 属性将以 nil 开始\N{\fs12}Like that NSString star contents property is going to start off nil.
Dialogue: 0,0:49:21.24,0:49:25.50,yin,,0,0,0,,Objective-C 中所有属性都是以 0 开始\N{\fs12}All properties, in objective-C, all of them, start off zero.
Dialogue: 0,0:49:25.50,0:49:27.50,yin,,0,0,0,,对于指针 也就是 nil\N{\fs12}So for pointer, that's nil.
Dialogue: 0,0:49:27.50,0:49:30.80,yin,,0,0,0,,这是我们创建新纸牌时的 contents 属性\N{\fs12}So that contents property, when we create a new card,
Dialogue: 0,0:49:30.80,0:49:32.82,yin,,0,0,0,,它不会指向任何内容\N{\fs12}it's going to not point to any contents.
Dialogue: 0,0:49:32.84,0:49:35.50,yin,,0,0,0,,纸牌是空的 上面什么都没有\N{\fs12}That card's going to be blank, okay, it's not going to have anything on it.
Dialogue: 0,0:49:35.50,0:49:38.50,yin,,0,0,0,,能使用 setter 和 getter 很好\N{\fs12}So, it's nice to use the setter and getter,
Dialogue: 0,0:49:38.50,0:49:41.50,yin,,0,0,0,,我们实现我们自己的 setter 和 getter 来检验\N{\fs12}we implement our own setter and getter that will check to see
Dialogue: 0,0:49:41.50,0:49:43.83,yin,,0,0,0,,是不是 nil 如果不是 有时\N{\fs12}if it's nil, and if it's not, and sometimes,
Dialogue: 0,0:49:43.84,0:49:46.21,yin,,0,0,0,,不是对于 contents 而是对于其它属性\N{\fs12}not with contents, but with some properties,
Dialogue: 0,0:49:46.21,0:49:49.50,yin,,0,0,0,,如果是 nil 我们将在内存中创建一些东西\N{\fs12}if it's nil, we'll create something in memory.
Dialogue: 0,0:49:49.50,0:49:50.85,yin,,0,0,0,,这是另一个用它的原因\N{\fs12}So that's another reason you use it.
Dialogue: 0,0:49:50.87,0:49:55.50,yin,,0,0,0,,下一讲 你会看到我们使用属性是有各种原因的\N{\fs12}So you'll see all these reasons why we want properties in the next lecture basically.
Dialogue: 0,0:49:55.50,0:49:59.50,yin,,0,0,0,,下面 我们来看一个方法\N{\fs12}Alright, so now, let's look at a method.
Dialogue: 0,0:49:59.50,0:50:01.24,yin,,0,0,0,,一个很常规的方法\N{\fs12}Okay? Just a regular, old method.
Dialogue: 0,0:50:01.24,0:50:03.50,yin,,0,0,0,,你们见过一些方法 setter 和 getter 方法\N{\fs12}You've seen some methods, the setter and getter methods,
Dialogue: 0,0:50:03.50,0:50:06.82,yin,,0,0,0,,但我们希望有自己的方法 公共方法\N{\fs12}but what if we wanted to find our own method, our own public method,
Dialogue: 0,0:50:06.82,0:50:09.28,yin,,0,0,0,,我将定义这个方法为 match(匹配)\N{\fs12}so I'm going to define this method called match.
Dialogue: 0,0:50:09.28,0:50:12.59,yin,,0,0,0,,记得吧 我这里要为纸牌匹配游戏创建一个模型\N{\fs12}Remember that I'm building a model here for a card matching game,
Dialogue: 0,0:50:12.61,0:50:14.69,yin,,0,0,0,,我需要将所有纸牌放到屏幕上\N{\fs12}where I'm going to put all these cards on the screen
Dialogue: 0,0:50:14.69,0:50:16.50,yin,,0,0,0,,用户需要进行匹配\N{\fs12}and the user is going to try and match them.
Dialogue: 0,0:50:16.50,0:50:18.02,yin,,0,0,0,,选取匹配的那些\N{\fs12}Pick ones that match, alright?
Dialogue: 0,0:50:18.02,0:50:19.50,yin,,0,0,0,,所以我需要一个 match 方法\N{\fs12}So I need a match method.
Dialogue: 0,0:50:19.50,0:50:23.50,yin,,0,0,0,,这个方法告诉我两张纸牌是否匹配\N{\fs12}A method that tells me whether two cards match.
Dialogue: 0,0:50:23.50,0:50:26.50,yin,,0,0,0,,我想要让它保持简单\N{\fs12}Okay? So, I'm trying to make this simple,
Dialogue: 0,0:50:26.50,0:50:29.50,yin,,0,0,0,,所以我写了一个简单方法 语义如下\N{\fs12}so I've made a simple match method that has the following semantics.
Dialogue: 0,0:50:29.50,0:50:31.91,yin,,0,0,0,,它将另一张纸牌作为参数\N{\fs12}It takes another card as the argument,
Dialogue: 0,0:50:31.93,0:50:33.50,yin,,0,0,0,,它返回一个整数\N{\fs12}and it returns it an integer.
Dialogue: 0,0:50:33.50,0:50:36.96,yin,,0,0,0,,如果纸牌不匹配 该整数为 0\N{\fs12}That integer is zero if the cards don't match,
Dialogue: 0,0:50:36.96,0:50:42.50,yin,,0,0,0,,否则 匹配越好 整数值就越大\N{\fs12}otherwise, it's an integer that is higher, the better a match it is.
Dialogue: 0,0:50:42.50,0:50:45.50,yin,,0,0,0,,非常好的匹配可能是 1000\N{\fs12}Okay? So like a really good match might be a thousand,
Dialogue: 0,0:50:45.50,0:50:49.50,yin,,0,0,0,,不过不算很好的匹配可能只有 100 甚至 1\N{\fs12}but a not so good match might only be a hundred, and, or, or it could be one.
Dialogue: 0,0:50:49.50,0:50:53.67,yin,,0,0,0,,这个数字是多少的语义 完全取决于纸牌\N{\fs12}Now, the semantics of what that number is, totally depends on the cards,
Dialogue: 0,0:50:53.67,0:50:56.50,yin,,0,0,0,,因为我们只会将纸牌和其它纸牌进行匹配\N{\fs12}because we're only going to match cards against other cards, alright?
Dialogue: 0,0:50:56.50,0:50:58.91,yin,,0,0,0,,我们会弄清它们匹配得有多好\N{\fs12}And we're going to find out how good a match they are
Dialogue: 0,0:50:58.93,0:51:01.50,yin,,0,0,0,,不管 Card 类是什么\N{\fs12}by how that, whatever that card class is,
Dialogue: 0,0:51:01.50,0:51:05.50,yin,,0,0,0,,我们会有一个子类 叫作 PlayingCard\N{\fs12}and we're going to make a subclass of this class, called playing card,
Dialogue: 0,0:51:05.50,0:51:09.06,yin,,0,0,0,,它会给大小匹配更多分\N{\fs12}that's going to give more points for matching the rank, okay,
Dialogue: 0,0:51:09.06,0:51:11.50,yin,,0,0,0,,花色匹配得分相对较少\N{\fs12}than it is for matching the suit.
Dialogue: 0,0:51:11.50,0:51:16.50,yin,,0,0,0,,分数系统由 Card 的这个子类决定\N{\fs12}But that's up to subclasses of card to determine what the point system is.
Dialogue: 0,0:51:16.50,0:51:20.06,yin,,0,0,0,,这里我们的 match 方法\N{\fs12}So, for our implementation of match,
Dialogue: 0,0:51:20.06,0:51:23.06,yin,,0,0,0,,实现会非常简单\N{\fs12}we're going to do a really simple implementation, so,
Dialogue: 0,0:51:23.06,0:51:25.50,yin,,0,0,0,,首先假设它们不匹配\N{\fs12}first let's assume that they don't match.
Dialogue: 0,0:51:25.50,0:51:28.50,yin,,0,0,0,,这里设分数的局部变量 int score = 0\N{\fs12}Okay, so I just made this local variable int score equals zero,
Dialogue: 0,0:51:28.50,0:51:30.50,yin,,0,0,0,,这里是给变量赋值\N{\fs12}you can see that you can assign a variable,
Dialogue: 0,0:51:30.50,0:51:33.50,yin,,0,0,0,,实际上 所有局部变量默认值都是 0\N{\fs12}actually all local variables also start out zero,
Dialogue: 0,0:51:33.50,0:51:35.50,yin,,0,0,0,,所以这里其实并不真的需要 =0\N{\fs12}so I don't even really need that equals zero,
Dialogue: 0,0:51:35.50,0:51:37.50,yin,,0,0,0,,但我认为写明会更好\N{\fs12}but I'm a big believer in putting that in
Dialogue: 0,0:51:37.50,0:51:39.96,yin,,0,0,0,,毕竟这就是你想要的值\N{\fs12}if that's really, you know, what you intend,
Dialogue: 0,0:51:39.98,0:51:42.95,yin,,0,0,0,,这里我确实要让分数为 0\N{\fs12}and in this case I intend the score to be actually zero.
Dialogue: 0,0:51:42.96,0:51:46.50,yin,,0,0,0,,分数一直为 0 直到有纸牌匹配成功\N{\fs12}The score of this match until I go and see if these cards match, right?
Dialogue: 0,0:51:46.50,0:51:48.83,yin,,0,0,0,,这更多的是一种编程风格\N{\fs12}So it's just a kind of programming style thing here.
Dialogue: 0,0:51:48.85,0:51:51.50,yin,,0,0,0,,我怎么知道\N{\fs12}So, how am I going to tell
Dialogue: 0,0:51:51.50,0:51:56.96,yin,,0,0,0,,纸牌能够匹配和它比较的纸牌呢\N{\fs12}if this card that's been passed in match, matches the card that it's being sent to?
Dialogue: 0,0:51:56.98,0:52:02.13,yin,,0,0,0,,答案是 我将发送一些消息\N{\fs12}And the answer is I'm going to send some messages.
Dialogue: 0,0:52:02.28,0:52:04.50,yin,,0,0,0,,看到这里的开方括号了吗\N{\fs12}You see the open square brackets notation there,
Dialogue: 0,0:52:04.50,0:52:09.59,yin,,0,0,0,,这是你们第一次看到我在 Objective-C 中发送消息\N{\fs12}that's the first time you're seeing me send a message in objective-C,
Dialogue: 0,0:52:09.59,0:52:13.50,yin,,0,0,0,,这一行中我还将发送另外两条消息\N{\fs12}and I'm also sending two other messages in this one line.
Dialogue: 0,0:52:13.50,0:52:18.24,yin,,0,0,0,,card.contents 和 self.contents 看到它俩了吗\N{\fs12}Card.contents and self.contents, you see both of those,
Dialogue: 0,0:52:18.24,0:52:20.35,yin,,0,0,0,,这些也是消息发送\N{\fs12}those are message sends, as well.
Dialogue: 0,0:52:20.35,0:52:23.28,yin,,0,0,0,,这里有两种发送消息的语法\N{\fs12}So there's two different syntaxes here for sending a message.
Dialogue: 0,0:52:23.28,0:52:27.50,yin,,0,0,0,,一种是开方括号 等下我会具体讲到\N{\fs12}One is open square brackets, okay, and we'll talk about that one in a second.
Dialogue: 0,0:52:27.50,0:52:31.50,yin,,0,0,0,,另一种是点符号 例如 card.contents\N{\fs12}And another one is dot notation, card.contents.
Dialogue: 0,0:52:31.50,0:52:32.94,yin,,0,0,0,,什么时候使用呢\N{\fs12}When do we use them?
Dialogue: 0,0:52:32.96,0:52:37.50,yin,,0,0,0,,点符号只用于属性\N{\fs12}We only use the dot notation for properties.
Dialogue: 0,0:52:37.50,0:52:41.50,yin,,0,0,0,,这是调用属性 setter 和 getter 的方式 使用点符号\N{\fs12}That's how we call the setter and getter of properties, using dot notation.
Dialogue: 0,0:52:41.50,0:52:44.76,yin,,0,0,0,,这里我们调用的是 getter\N{\fs12}Okay? Now, here we're calling the getter,
Dialogue: 0,0:52:44.78,0:52:46.67,yin,,0,0,0,,card.contents 调用的是\N{\fs12}card.contents is calling
Dialogue: 0,0:52:46.67,0:52:52.50,yin,,0,0,0,,card 实例 contents 属性的 getter 方法\N{\fs12}the getter of the contents property on the card instance.
Dialogue: 0,0:52:52.50,0:52:54.50,yin,,0,0,0,,如何调用 setter 呢\N{\fs12}How do we call the setter?
Dialogue: 0,0:52:54.50,0:52:55.50,yin,,0,0,0,,完全一样\N{\fs12}Exactly the same.
Dialogue: 0,0:52:55.50,0:52:59.50,yin,,0,0,0,,card.contents 但是要放在等号左侧\N{\fs12}Card.contents, but we put it on the left-hand side of the equals.
Dialogue: 0,0:52:59.50,0:53:01.15,yin,,0,0,0,,card.contents =\N{\fs12}Card.contents equals,
Dialogue: 0,0:53:01.15,0:53:04.50,yin,,0,0,0,,这就是调用 contents 的 setter 明白吗\N{\fs12}now we're calling the setter for contents. You see?
Dialogue: 0,0:53:04.50,0:53:06.07,yin,,0,0,0,,这里我们在调用 getter\N{\fs12}So here we're calling the getter.
Dialogue: 0,0:53:06.09,0:53:09.76,yin,,0,0,0,,我们还为 self(自身) 的 contents 调用了 getter\N{\fs12}We're also calling the getter for contents on self, on our self.
Dialogue: 0,0:53:09.78,0:53:12.50,yin,,0,0,0,,其它语言中 这个可能用的是 this\N{\fs12}So, in other language this might be called this, right,
Dialogue: 0,0:53:12.50,0:53:14.33,yin,,0,0,0,,但你们知道 self 是什么\N{\fs12}but you know what self is, right, self is
Dialogue: 0,0:53:14.33,0:53:17.50,yin,,0,0,0,,self 也就是这段代码正在起作用的实例\N{\fs12}this instance that this code is operating on.
Dialogue: 0,0:53:17.50,0:53:20.78,yin,,0,0,0,,我们将对比这两个字符串\N{\fs12}So, we are going to compare these two strings,
Dialogue: 0,0:53:20.78,0:53:23.15,yin,,0,0,0,,card.contents 和 self.contents\N{\fs12}card.contents and self.contents
Dialogue: 0,0:53:23.15,0:53:25.50,yin,,0,0,0,,看它们是否相等\N{\fs12}to see if they are equal and we are going to do
Dialogue: 0,0:53:25.50,0:53:30.03,yin,,0,0,0,,使用的是 NSString 方法 isEqualToString:\N{\fs12}that with the NSString method is equal to string colon.
Dialogue: 0,0:53:30.04,0:53:34.41,yin,,0,0,0,,isEqualToString: 只能被发送给一个字符串\N{\fs12}So isEqualToString colon can only be sent to a string,
Dialogue: 0,0:53:35.18,0:53:38.35,yin,,0,0,0,,isEqualToString 只能被发送给一个字符串\N{\fs12}so isEqualToString can only be sent to a string
Dialogue: 0,0:53:38.35,0:53:40.16,yin,,0,0,0,,而 card.contents\N{\fs12}and card.contents
Dialogue: 0,0:53:40.17,0:53:42.85,yin,,0,0,0,,是一个返回 NSString 的 getter 方法\N{\fs12}is a getter method that returns a NSString,
Dialogue: 0,0:53:42.85,0:53:43.83,yin,,0,0,0,,这很好\N{\fs12}so we're good to go, right?
Dialogue: 0,0:53:43.85,0:53:46.63,yin,,0,0,0,,我们将 isEqualToString 发送给一个字符串\N{\fs12}We're sending is equal string to a string,
Dialogue: 0,0:53:46.63,0:53:50.79,yin,,0,0,0,,而且 isEqualToString 将一个 NSString 作为参数\N{\fs12}and isEqualToString takes as an argument, an NSString
Dialogue: 0,0:53:50.79,0:53:52.09,yin,,0,0,0,,重复一次 self.contents\N{\fs12}and, again, self.contents
Dialogue: 0,0:53:52.09,0:53:54.50,yin,,0,0,0,,是返回 NSString 的 getter 方法\N{\fs12}is a getter method that returns NSString;
Dialogue: 0,0:53:54.50,0:53:58.41,yin,,0,0,0,,这样 我们就满足了 isEqualToString 的所有要求\N{\fs12}therefore, we have satisfied all the requirements of is equal to string
Dialogue: 0,0:53:58.42,0:54:00.50,yin,,0,0,0,,外面打上方括号\N{\fs12}and we put square brackets around it,
Dialogue: 0,0:54:00.50,0:54:02.50,yin,,0,0,0,,这会返回一个布尔值\N{\fs12}and it's going to return a Boolean is
Dialogue: 0,0:54:02.50,0:54:05.15,yin,,0,0,0,,isEqualToString 的作用是返回布尔值\N{\fs12}equal to string is defined to return a Boolean
Dialogue: 0,0:54:05.15,0:54:07.50,yin,,0,0,0,,看两个字符串是否相同\N{\fs12}whether the contents of those two strings are the same.
Dialogue: 0,0:54:07.50,0:54:10.50,yin,,0,0,0,,注意到这里用的不是 ==\N{\fs12}Notice we did not say equals equals.
Dialogue: 0,0:54:10.50,0:54:14.29,yin,,0,0,0,,我们没有说 card.contents == self.contents\N{\fs12}We did not say card.contents equals equals self.contents.
Dialogue: 0,0:54:14.29,0:54:16.50,yin,,0,0,0,,因为 == 比较的是指针\N{\fs12}Because we'd just be comparing the pointers then,
Dialogue: 0,0:54:16.50,0:54:20.50,yin,,0,0,0,,而不是指针指向的内容\N{\fs12}not what the pointers point to.
Dialogue: 0,0:54:20.50,0:54:24.13,yin,,0,0,0,,大家明白为什么不用 == 来看两字符串是否相等了吗\N{\fs12}Everyone understand why we didn't use == to see if those two strings are the same?
Dialogue: 0,0:54:24.15,0:54:27.50,yin,,0,0,0,,如果两个字符串相等 我将给 1 分\N{\fs12}So if those strings are the same, I'm going to give one point.
Dialogue: 0,0:54:27.50,0:54:32.18,yin,,0,0,0,,这是一种极度简单化的匹配实现\N{\fs12}So this is either the dirt simple implementation of match,
Dialogue: 0,0:54:32.18,0:54:35.50,yin,,0,0,0,,也就是 如果纸牌内容完全相同\N{\fs12}which is if the cards are exactly the same, their contents are exactly the same,
Dialogue: 0,0:54:35.50,0:54:38.13,yin,,0,0,0,,我得到 1 分 否则得 0 分\N{\fs12}I'll get one point, otherwise I get zero.
Dialogue: 0,0:54:38.15,0:54:42.50,yin,,0,0,0,,后面在 PlayingCard 中 匹配实现会更好一些\N{\fs12}Now we're going to do much better implementation in match when we do playing card,
Dialogue: 0,0:54:42.50,0:54:44.50,yin,,0,0,0,,这里只是一个极简单的例子\N{\fs12}but this is our kind of dirt simple one.
Dialogue: 0,0:54:44.50,0:54:48.50,yin,,0,0,0,,关于 Objective-C 我再讲一点\N{\fs12}Now, to give you just a little more about objective-C,
Dialogue: 0,0:54:48.50,0:54:50.50,yin,,0,0,0,,如果我们改变这个方法… 哦 对\N{\fs12}what if we changed this method, oh, so, yeah,
Dialogue: 0,0:54:50.50,0:54:55.50,yin,,0,0,0,,这是关于谁是发送者 谁是接收者的一点内容\N{\fs12}here's a little bit about who's the sender and who's the receiver here.
Dialogue: 0,0:54:55.50,0:54:57.50,yin,,0,0,0,,你们可以自己看这些幻灯片\N{\fs12}You can look at this in the slides later.
Dialogue: 0,0:54:57.50,0:55:00.50,yin,,0,0,0,,不过我打算让这个更复杂一些\N{\fs12}Okay? But I'm going to make this a little more complicated.
Dialogue: 0,0:55:00.50,0:55:04.50,yin,,0,0,0,,我将让 match 的参数是一个纸牌的数组\N{\fs12}I'm going to make the argument to match be an array of cards.
Dialogue: 0,0:55:04.50,0:55:09.50,yin,,0,0,0,,现在我要将这张牌 同其它很多牌进行匹配\N{\fs12}So now I'm matching this card that I'm sending this to, to a whole bunch of other cards.
Dialogue: 0,0:55:10.07,0:55:14.50,yin,,0,0,0,,现在我需要新的算法来匹配\N{\fs12}So now I'm going to need some new algorithm to match, right?
Dialogue: 0,0:55:14.50,0:55:16.50,yin,,0,0,0,,这里纸牌的匹配还是\N{\fs12}So, again, a playing card match,
Dialogue: 0,0:55:16.50,0:55:18.50,yin,,0,0,0,,假设要匹配三张牌\N{\fs12}if let's say you had matching three cards,
Dialogue: 0,0:55:18.50,0:55:21.70,yin,,0,0,0,,如果三张牌大小都一样 你能得很多分\N{\fs12}you might give a lot of points if all three cards are the same rank,
Dialogue: 0,0:55:21.70,0:55:24.11,yin,,0,0,0,,例如都是 J 你会得到很多分\N{\fs12}they're all jacks, you get a lot of points.
Dialogue: 0,0:55:24.13,0:55:26.50,yin,,0,0,0,,如果只有两张是 J 其它都是别的\N{\fs12}If only two of them are jacks and the other one is something else,
Dialogue: 0,0:55:26.50,0:55:28.50,yin,,0,0,0,,你就没有之前得分多\N{\fs12}well you don't get very many points at all.
Dialogue: 0,0:55:28.50,0:55:31.11,yin,,0,0,0,,如果它们都是相同花色 你会得到中等量的分\N{\fs12}If they're all through the same suit, you kind of get a medium amount of points,
Dialogue: 0,0:55:31.11,0:55:32.50,yin,,0,0,0,,知道我讲的什么吗\N{\fs12}you see what I mean? So,
Dialogue: 0,0:55:32.50,0:55:37.50,yin,,0,0,0,,这里 match 的参数是一整个数组 而不只是一张牌\N{\fs12}here I'm changing match to take an array as the argument instead of just a single card.
Dialogue: 0,0:55:37.50,0:55:41.20,yin,,0,0,0,,如何改变实现来应对这个呢\N{\fs12}And how would I change my implementation to deal with that?
Dialogue: 0,0:55:41.20,0:55:44.50,yin,,0,0,0,,这里我将使用一个 for 循环在if外\N{\fs12}Well, I'm just going to put a for-loop around my if
Dialogue: 0,0:55:44.50,0:55:47.02,yin,,0,0,0,,遍历所有纸牌\N{\fs12}and iterate through all the cards
Dialogue: 0,0:55:47.03,0:55:51.20,yin,,0,0,0,,这种实现 但愿你们能很快反应过来\N{\fs12}and so this implementation, hopefully those of you who are quick thinkers,
Dialogue: 0,0:55:51.20,0:55:52.50,yin,,0,0,0,,这有什么用\N{\fs12}you can know what this does,
Dialogue: 0,0:55:52.50,0:55:53.85,yin,,0,0,0,,这会在\N{\fs12}this gives you one point
Dialogue: 0,0:55:53.85,0:55:58.50,yin,,0,0,0,,纸牌同数组中任何一张纸牌匹配时给你 1 分\N{\fs12}if the card that's receiving this matches any of the cards in the array.
Dialogue: 0,0:55:58.50,0:56:01.09,yin,,0,0,0,,任何一张 不是所有 而是任一\N{\fs12}Any, not all, any.
Dialogue: 0,0:56:01.09,0:56:03.50,yin,,0,0,0,,当然 你们也可以想象更好的算法\N{\fs12}Now you can imagine a lot better algorithms here.
Dialogue: 0,0:56:03.50,0:56:07.00,yin,,0,0,0,,例如数组中每匹配上一张牌就得 1 分\N{\fs12}Maybe you get one point for every card you match in the array
Dialogue: 0,0:56:07.01,0:56:10.89,yin,,0,0,0,,或者匹配一个得 2 分 两个 4 分 三个 8 分\N{\fs12}or you get two points for one match and four points for two and eight points for three,
Dialogue: 0,0:56:10.90,0:56:14.50,yin,,0,0,0,,使用某种指数得分算法\N{\fs12}some sort of binary thing, exponential point, whatever,
Dialogue: 0,0:56:14.50,0:56:16.53,yin,,0,0,0,,但今天只是第一天课\N{\fs12}this is first day of lecture,
Dialogue: 0,0:56:16.53,0:56:19.14,yin,,0,0,0,,弄简单一些 有任意一个匹配就得 1 分\N{\fs12}we're just going to give one point if it matches any.
Dialogue: 0,0:56:19.16,0:56:21.42,yin,,0,0,0,,这里我只是想展示给大家\N{\fs12}But mostly what I wanted to show you here is
Dialogue: 0,0:56:21.42,0:56:25.50,yin,,0,0,0,,参数中如果是一个数组 而不是一张牌时会怎样\N{\fs12}what it looks like to have an array as the argument instead of a single card.
Dialogue: 0,0:56:25.50,0:56:29.07,yin,,0,0,0,,让你们理解方法的参数是什么\N{\fs12}So that you understand that the argument, what the argument to the method is
Dialogue: 0,0:56:29.07,0:56:31.87,yin,,0,0,0,,同时我还想展示 for 循环\N{\fs12}and also so I can show you the for-loop there.
Dialogue: 0,0:56:31.88,0:56:35.50,yin,,0,0,0,,这里有 for in 很多语言中现在都有这样的结构\N{\fs12}You see that for in, a lot of languages have that these days.
Dialogue: 0,0:56:35.50,0:56:37.77,yin,,0,0,0,,也就是说它是一个 for 循环\N{\fs12}That just basically means it's a for-loop
Dialogue: 0,0:56:37.77,0:56:41.37,yin,,0,0,0,,它会遍历 NSArray 中的每一个对象\N{\fs12}where it's going to go through every object in that NSArray
Dialogue: 0,0:56:41.37,0:56:43.00,yin,,0,0,0,,将它赋值给 card\N{\fs12}and assign it to card,
Dialogue: 0,0:56:43.01,0:56:44.75,yin,,0,0,0,,card 是迭代变量\N{\fs12}card is the iteration variable,
Dialogue: 0,0:56:44.75,0:56:48.00,yin,,0,0,0,,对于数组中每一张牌执行一次 if\N{\fs12}and execute that if once for each of the cards in the array.
Dialogue: 0,0:56:48.01,0:56:49.94,yin,,0,0,0,,大家都能理解这个吗\N{\fs12}Everyone understand that?
Dialogue: 0,0:56:49.94,0:56:52.50,yin,,0,0,0,,有问题的话请提出来\N{\fs12}If you have a question about that, ask?
Dialogue: 0,0:56:53.01,0:56:54.38,yin,,0,0,0,,请讲\N{\fs12}Yeah?
Dialogue: 0,0:56:58.57,0:57:00.50,yin,,0,0,0,,哦 好 问得很好\N{\fs12}Oh, okay. That's a great question.
Dialogue: 0,0:57:00.50,0:57:04.50,yin,,0,0,0,,问题是 for 行如果写 for Card card\N{\fs12}So the question is if I just have that for line, but I said for card card,
Dialogue: 0,0:57:04.50,0:57:09.12,yin,,0,0,0,,而不是 for Card *card in otherCards 会怎样\N{\fs12}not for card star card in other cards.
Dialogue: 0,0:57:09.12,0:57:11.70,yin,,0,0,0,,我们会得到语法错误 为什么\N{\fs12}We'd get a syntax error. Why?
Dialogue: 0,0:57:11.74,0:57:15.50,yin,,0,0,0,,因为所有对象都有指针指着 所以总有这个星号\N{\fs12}Because all objects are always pointed to so we always have that star.
Dialogue: 0,0:57:15.50,0:57:17.50,yin,,0,0,0,,总是\N{\fs12}Always.
Dialogue: 0,0:57:17.50,0:57:22.00,yin,,0,0,0,,没有哪张牌没有指针指着\N{\fs12}You can't have a card not being a pointer to it,
Dialogue: 0,0:57:22.03,0:57:25.50,yin,,0,0,0,,所以这里 Objective-C 会告诉你语法错误\N{\fs12}so the, you know, objective-C would give you a syntax error there,
Dialogue: 0,0:57:25.50,0:57:27.50,yin,,0,0,0,,不能没有这个星号\N{\fs12}it's impossible to not have that star.
Dialogue: 0,0:57:27.50,0:57:31.18,yin,,0,0,0,,有类名时 就总得有这个星号 请讲\N{\fs12}Whenever you have the name of the class, it's always going to have that star. Yeah?
Dialogue: 0,0:57:35.72,0:57:37.94,yin,,0,0,0,,是 问题问得很好\N{\fs12}Yes. The question is, another great one,
Dialogue: 0,0:57:37.96,0:57:41.25,yin,,0,0,0,,我能否使用方括号来调用 setter 和 getter\N{\fs12}can I use the square brackets to call the setter and getter
Dialogue: 0,0:57:41.25,0:57:43.16,yin,,0,0,0,,来代替点符号\N{\fs12}instead of using that dot notation?
Dialogue: 0,0:57:43.18,0:57:46.81,yin,,0,0,0,,这个问题很有深度 答案是完全可以\N{\fs12}And that's a really insightful question and the answer is absolutely you can,
Dialogue: 0,0:57:46.81,0:57:50.50,yin,,0,0,0,,这完全是合法的 因为 setter 和 getter 也是正常的方法\N{\fs12}it's perfectly legal, because that setter and getter are completely normal methods.
Dialogue: 0,0:57:50.50,0:57:52.50,yin,,0,0,0,,它们没有什么特殊之处\N{\fs12}There's nothing special about them whatsoever.
Dialogue: 0,0:57:52.50,0:57:57.50,yin,,0,0,0,,点符号只是语法上一点精简 一点甜头\N{\fs12}That dot notation is a nicety, syntactic sugar only.
Dialogue: 0,0:57:57.50,0:58:00.86,yin,,0,0,0,,如果问题是 sette r和 getter 是否应该用方括号\N{\fs12}The question is should you use square brackets for setter and getter,
Dialogue: 0,0:58:00.86,0:58:02.90,yin,,0,0,0,,我想这是风格问题\N{\fs12}and I think it's a matter of style.
Dialogue: 0,0:58:02.90,0:58:05.14,yin,,0,0,0,,反正你需要 100% 保持一致\N{\fs12}You would definitely would want to be 100 percent consistent,
Dialogue: 0,0:58:05.14,0:58:06.50,yin,,0,0,0,,不要混用\N{\fs12}you would never want to mix them.
Dialogue: 0,0:58:06.50,0:58:10.31,yin,,0,0,0,,我想大多数人都会用点符号\N{\fs12}And I think most people, most people would say use the dot notation.
Dialogue: 0,0:58:10.31,0:58:13.50,yin,,0,0,0,,这会更清楚 更简单 更美观\N{\fs12}It makes it clearer, it's a little simpler, nicer,
Dialogue: 0,0:58:13.50,0:58:15.29,yin,,0,0,0,,但是你也可以不这样\N{\fs12}but, you know, you could.
Dialogue: 0,0:58:15.29,0:58:17.18,yin,,0,0,0,,这门课中请使用点符号\N{\fs12}In this class, please use the dot notation
Dialogue: 0,0:58:17.18,0:58:19.50,yin,,0,0,0,,我要确保你们懂得如何用点符号\N{\fs12}just so I know you know how to use dot notation.
Dialogue: 0,0:58:19.50,0:58:20.42,yin,,0,0,0,,有问题\N{\fs12}Question?
Dialogue: 0,0:58:24.86,0:58:26.50,yin,,0,0,0,,又是一个很棒的问题\N{\fs12}OK, awesome question again.
Dialogue: 0,0:58:26.50,0:58:28.12,yin,,0,0,0,,天啊 你们太厉害了\N{\fs12}Gosh, you guys are so good.
Dialogue: 0,0:58:28.14,0:58:32.50,yin,,0,0,0,,我能否将点符号用于 getter 和 setter 之外\N{\fs12}Can I use dot notation for a method that takes no arguments,
Dialogue: 0,0:58:32.50,0:58:34.50,yin,,0,0,0,,一个没有参数的方法\N{\fs12}but is not a getter or a setter?
Dialogue: 0,0:58:34.50,0:58:37.92,yin,,0,0,0,,答案是这样做的话 Objective-C 会警告你\N{\fs12}And the answer is objective-C will warn you about that,
Dialogue: 0,0:58:37.94,0:58:39.83,yin,,0,0,0,,不是错误 而是警告\N{\fs12}not give you an error, but warn you,
Dialogue: 0,0:58:39.85,0:58:41.88,yin,,0,0,0,,这门课中不可以这样做\N{\fs12}and you should never do that in this class.
Dialogue: 0,0:58:41.90,0:58:44.31,yin,,0,0,0,,这不是一个很好的做法\N{\fs12}Okay? That is really not that good form,
Dialogue: 0,0:58:44.31,0:58:46.88,yin,,0,0,0,,他所讲的那个还可以探讨\N{\fs12}whereas his question was kind of like you can argue,
Dialogue: 0,0:58:46.90,0:58:48.75,yin,,0,0,0,,但你这个 不要这样做\N{\fs12}that one, don't do it.
Dialogue: 0,0:58:48.77,0:58:52.50,yin,,0,0,0,,点符号只能用于 setter 和 getter\N{\fs12}So. Use dot notations only for setters and getters.
Dialogue: 0,0:58:52.50,0:58:53.50,yin,,0,0,0,,还有问题吗\N{\fs12}Other questions?
Dialogue: 0,0:58:55.07,0:58:56.05,yin,,0,0,0,,请讲\N{\fs12}Yeah?
Dialogue: 0,0:58:59.50,0:59:02.50,yin,,0,0,0,,问题是 如何用点符号来使用 setter\N{\fs12}So, yeah, question is how do you use a setter with dot notation?
Dialogue: 0,0:59:02.50,0:59:04.50,yin,,0,0,0,,同 getter 完全一样\N{\fs12}And it's exactly the same as a getter,
Dialogue: 0,0:59:04.50,0:59:07.50,yin,,0,0,0,,只是需要用到等号的左边\N{\fs12}it's just that you're using it on the left-hand side of an equals.
Dialogue: 0,0:59:07.50,0:59:12.16,yin,,0,0,0,,例如 card.contents 等号 梅花 A\N{\fs12}So card.contents equals, you know, A of clubs,
Dialogue: 0,0:59:12.16,0:59:15.50,yin,,0,0,0,,这就会调用 contents 的 setter\N{\fs12}that would call the setter of contents, whereas, you know,
Dialogue: 0,0:59:15.50,0:59:19.84,yin,,0,0,0,,这里则会调用 getter 因为它没在等号左侧\N{\fs12}this is calling the getter, because it's not on the left-hand side of the equal.
Dialogue: 0,0:59:21.47,0:59:23.36,yin,,0,0,0,,很好 今天就这些了\N{\fs12}Excellent! That's all I had today, so
Dialogue: 0,0:59:23.36,0:59:26.81,yin,,0,0,0,,周三 我会讲 Deck\N{\fs12}on Wednesday, we will do deck
Dialogue: 0,0:59:26.83,0:59:29.53,yin,,0,0,0,,PlayingCard 和 PlayingCardDeck\N{\fs12}and playing card and playing card
Dialogue: 0,0:59:29.53,0:59:33.50,yin,,0,0,0,,我会详细讲解 XCode 5 中的一个经典 demo\N{\fs12}and I'm going to dive right into a big old demo of XCode 5
Dialogue: 0,0:59:33.50,0:59:35.50,yin,,0,0,0,,看这些实际是怎么做到的\N{\fs12}and show you how all this stuff is actually done,
Dialogue: 0,0:59:35.50,0:59:38.50,yin,,0,0,0,,下周 我们会更进一步讲 Objective-C\N{\fs12}and then next week we'll do, yet more objective-C.
Dialogue: 0,0:59:38.50,0:59:40.40,yin,,0,0,0,,非常感谢大家\N{\fs12}Thank you very much!
Dialogue: 0,0:59:41.72,0:59:45.66,yin,,0,0,0,,更多内容 请访问我校官网 stanford.edu\N{\fs12}For more, please visit us at stanford.edu.


================================================
FILE: Subtitles/10. Multithreading, Scroll View.ass
================================================
[Script Info]
; Script generated by Aegisub 3.2.0
; http://www.aegisub.org/
Title: Default Aegisub file
ScriptType: v4.00+
WrapStyle: 0
ScaledBorderAndShadow: yes
YCbCr Matrix: None

[Aegisub Project Garbage]
Last Style Storage: Default

[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: yin,冬青黑体简体中文 W3,20,&H00FFFFFF,&HF0000000,&H00000000,&H32000000,0,0,0,0,100,100,0,0,1,1,0,2,5,5,5,134

[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:05.41,0:00:06.41,yin,,0,0,0,,斯坦福大学\N{\fs12}Stanford University.
Dialogue: 0,0:00:08.62,0:00:13.34,yin,,0,0,0,,欢迎来到2013至2014秋季学期\N{\fs12}Okay, well, welcome then to lecture 10, yes 10,
Dialogue: 0,0:00:13.63,0:00:17.62,yin,,0,0,0,,CS193P第十讲\N{\fs12}of CS193P, fall of 2013/14 academic year,
Dialogue: 0,0:00:17.63,0:00:20.77,yin,,0,0,0,,今天我们要讲的是多线程\N{\fs12}and today, we are going to talk about multithreading.
Dialogue: 0,0:00:20.87,0:00:22.75,yin,,0,0,0,,我只会简单地讲一下\N{\fs12}Okay? I'm only going to talk about it briefly,
Dialogue: 0,0:00:24.43,0:00:26.87,yin,,0,0,0,,因为很多多线程的内容\N{\fs12}but, because you'll learn a lot from multithreading
Dialogue: 0,0:00:26.88,0:00:28.29,yin,,0,0,0,,都会通过实际体验学到\N{\fs12}kind of through experience.
Dialogue: 0,0:00:28.98,0:00:30.48,yin,,0,0,0,,然后我们会讲UIScrollView滚动视图\N{\fs12}Then we're going to talk about UIScrollView,
Dialogue: 0,0:00:30.48,0:00:32.32,yin,,0,0,0,,非常重要的视图\N{\fs12}a very important view that allows you
Dialogue: 0,0:00:32.32,0:00:36.28,yin,,0,0,0,,能够扩大手机小屏幕的范围\N{\fs12}to expand what you can see on that little phone screen,
Dialogue: 0,0:00:36.37,0:00:38.09,yin,,0,0,0,,让你看到更大的内容\N{\fs12}to let you look at larger things.
Dialogue: 0,0:00:38.39,0:00:40.88,yin,,0,0,0,,然后我会做一个示例演示 包含这两项内容\N{\fs12}I'll do a demo that's gonna cover both of those things,
Dialogue: 0,0:00:40.88,0:00:42.17,yin,,0,0,0,,多线程和滚动视图\N{\fs12}multithreading and scrolling.
Dialogue: 0,0:00:42.43,0:00:44.14,yin,,0,0,0,,然后剩下的时间\N{\fs12}And then however much time we'll have left
Dialogue: 0,0:00:44.15,0:00:46.86,yin,,0,0,0,,我们会开始讲下一个主题UITableView表视图\N{\fs12}we'll get started on our next topic which is UITableView,
Dialogue: 0,0:00:46.86,0:00:49.75,yin,,0,0,0,,周三再继续\N{\fs12}we'll continue that on Wednesday.
Dialogue: 0,0:00:51.97,0:00:53.40,yin,,0,0,0,,先来看多线程\N{\fs12}So multithreading, okay.
Dialogue: 0,0:00:54.13,0:00:56.48,yin,,0,0,0,,多线程就是\N{\fs12}The idea with multithreading is
Dialogue: 0,0:00:56.67,0:01:00.80,yin,,0,0,0,,将程序的执行路径\N{\fs12}that you want to divide up the execution paths of your program
Dialogue: 0,0:01:00.81,0:01:04.00,yin,,0,0,0,,分为不同的路径\N{\fs12}into different and distinct paths
Dialogue: 0,0:01:04.01,0:01:06.64,yin,,0,0,0,,可能在同一时间运行\N{\fs12}that are possibly running at the same time.
Dialogue: 0,0:01:06.64,0:01:09.63,yin,,0,0,0,,我说"可能" 因为从程序员的角度看\N{\fs12}Now I say possibly, from your standpoint as a programmer,
Dialogue: 0,0:01:09.63,0:01:11.49,yin,,0,0,0,,各个线程都是同时运行的\N{\fs12}they look like they're all running at the same time.
Dialogue: 0,0:01:11.74,0:01:14.09,yin,,0,0,0,,但是 如果你的电脑或者手机\N{\fs12}But, of course, if you have a computer or a phone
Dialogue: 0,0:01:14.09,0:01:15.72,yin,,0,0,0,,只有一个处理器\N{\fs12}that only has one processor,
Dialogue: 0,0:01:15.90,0:01:17.90,yin,,0,0,0,,根本不可能同时运行\N{\fs12}there's no way for them to run at the same time.
Dialogue: 0,0:01:18.19,0:01:20.42,yin,,0,0,0,,但是操作系统让它们看起来是同时处理的\N{\fs12}But the OS makes it appear that they are
Dialogue: 0,0:01:20.42,0:01:22.26,yin,,0,0,0,,方法主要是时间分片\N{\fs12}by basically time slicing,
Dialogue: 0,0:01:22.27,0:01:24.58,yin,,0,0,0,,分给每个进程一点时间\N{\fs12}giving each one of them a little bit of time
Dialogue: 0,0:01:25.64,0:01:28.16,yin,,0,0,0,,这样看起来它们都是同时运行的\N{\fs12}to make it seem like they're all running at the same time, okay?
Dialogue: 0,0:01:28.78,0:01:33.00,yin,,0,0,0,,如果你确实有多个处理器\N{\fs12}And, so, if you did have a multiprocessor,
Dialogue: 0,0:01:33.00,0:01:35.45,yin,,0,0,0,,它们可能会同时运行 可能不会\N{\fs12}maybe they would actually running at the same time, or maybe not,
Dialogue: 0,0:01:35.46,0:01:36.86,yin,,0,0,0,,但我们不在意也不知道\N{\fs12}but you don't care and you don't know.
Dialogue: 0,0:01:37.14,0:01:39.82,yin,,0,0,0,,不是我们要知道的内容\N{\fs12}Okay? It's totally not for you to know.
Dialogue: 0,0:01:40.01,0:01:41.95,yin,,0,0,0,,我们为什么需要这种行为呢\N{\fs12}Why do we want this kind of behavior
Dialogue: 0,0:01:41.95,0:01:43.69,yin,,0,0,0,,这种多线程执行\N{\fs12}where we have these multiple threads of execution?
Dialogue: 0,0:01:43.69,0:01:45.40,yin,,0,0,0,,有一些原因\N{\fs12}Well, a couple of reasons.
Dialogue: 0,0:01:45.40,0:01:47.26,yin,,0,0,0,,有一个执行线程\N{\fs12}One, we've got one thread of execution
Dialogue: 0,0:01:47.27,0:01:49.39,yin,,0,0,0,,也就是主执行线程\N{\fs12}which is that main thread of execution
Dialogue: 0,0:01:49.50,0:01:51.73,yin,,0,0,0,,用户在其中互动 执行触控事件\N{\fs12}where the user is interacting, doing touch events,
Dialogue: 0,0:01:51.74,0:01:53.74,yin,,0,0,0,,我们希望它有很好的响应能力\N{\fs12}we want thing to be very responsive.
Dialogue: 0,0:01:53.90,0:01:55.85,yin,,0,0,0,,我们想让它始终在监听\N{\fs12}We want that to always be listening,
Dialogue: 0,0:01:55.87,0:01:57.49,yin,,0,0,0,,不想让它停止监听\N{\fs12}we never want that to not be listening.
Dialogue: 0,0:01:58.06,0:01:59.94,yin,,0,0,0,,另外一个原因就是其他执行线程\N{\fs12}The other thing is we have other threads of execution
Dialogue: 0,0:01:59.94,0:02:02.27,yin,,0,0,0,,可能会阻塞\N{\fs12}that actually might block, okay?
Dialogue: 0,0:02:02.27,0:02:03.34,yin,,0,0,0,,为什么会阻塞呢\N{\fs12}Why would they block?
Dialogue: 0,0:02:03.34,0:02:04.25,yin,,0,0,0,,为什么会停下来\N{\fs12}Why would they stop?
Dialogue: 0,0:02:04.32,0:02:06.27,yin,,0,0,0,,比如说执行了一个网络调用\N{\fs12}Well, let's say they do a network call
Dialogue: 0,0:02:06.29,0:02:08.28,yin,,0,0,0,,等待返回网络数据\N{\fs12}and they're waiting for something to come back over the network.
Dialogue: 0,0:02:08.28,0:02:10.71,yin,,0,0,0,,需要等待返回的内容\N{\fs12}Well, they have to wait for that thing to come back.
Dialogue: 0,0:02:10.71,0:02:12.36,yin,,0,0,0,,所以线程会被阻塞 会停住\N{\fs12}So they are blocked, they're stopped.
Dialogue: 0,0:02:12.80,0:02:14.81,yin,,0,0,0,,我们不会希望主线程\N{\fs12}Okay? We would never want that main execution
Dialogue: 0,0:02:14.82,0:02:16.17,yin,,0,0,0,,监听触控事件的主线程\N{\fs12}that's listening for touch events
Dialogue: 0,0:02:16.18,0:02:19.13,yin,,0,0,0,,被停住或被阻塞\N{\fs12}to be stopped, okay, or blocked, right?
Dialogue: 0,0:02:19.18,0:02:21.07,yin,,0,0,0,,但是其他线程阻塞就没关系了\N{\fs12}But these other ones, it's okay if they're blocked.
Dialogue: 0,0:02:21.07,0:02:22.17,yin,,0,0,0,,如果它们在等待返回数据\N{\fs12}If they're waiting for something,
Dialogue: 0,0:02:22.20,0:02:24.01,yin,,0,0,0,,等待就可以了\N{\fs12}they're waiting for something. Okay?
Dialogue: 0,0:02:24.59,0:02:28.02,yin,,0,0,0,,想要理解iOS中多线程的实现方法\N{\fs12}So to understand how we do multithreading, in iOS,
Dialogue: 0,0:02:28.16,0:02:31.19,yin,,0,0,0,,有一点要理解 也就是queue队列\N{\fs12}there's one thing you have to understand and that's queues.
Dialogue: 0,0:02:31.73,0:02:34.92,yin,,0,0,0,,队列和现实世界中的队列是一样的\N{\fs12}Okay? A queue, just like a queue in the real world,
Dialogue: 0,0:02:34.93,0:02:35.95,yin,,0,0,0,,队列表示排成一队\N{\fs12}queue means like a line,
Dialogue: 0,0:02:35.96,0:02:38.01,yin,,0,0,0,,比如你去电影院 人们会排成一队\N{\fs12}like you go to the movie theater and there's a line of people,
Dialogue: 0,0:02:38.02,0:02:38.93,yin,,0,0,0,,这叫做队列\N{\fs12}that's called a queue.
Dialogue: 0,0:02:39.29,0:02:40.52,yin,,0,0,0,,向不知道这个词的同学解释一下\N{\fs12}For those of you who don't know that word.
Dialogue: 0,0:02:41.30,0:02:42.86,yin,,0,0,0,,如果理解了这个队列的意思\N{\fs12}And so you got that queue
Dialogue: 0,0:02:42.87,0:02:46.02,yin,,0,0,0,,iOS多线程这里的队列也是一样的\N{\fs12}and the same thing is happening here with iOS multithreading.
Dialogue: 0,0:02:46.02,0:02:48.10,yin,,0,0,0,,这里也有队列 但在这些队列中\N{\fs12}You have these queues, but in these queues,
Dialogue: 0,0:02:48.10,0:02:51.70,yin,,0,0,0,,不是等着看电影的人 而是block\N{\fs12}instead of people waiting for the theater, there are blocks.
Dialogue: 0,0:02:51.88,0:02:53.99,yin,,0,0,0,,上周我们讲过的block\N{\fs12}Blocks in the way we talked about last week.
Dialogue: 0,0:02:53.99,0:02:56.24,yin,,0,0,0,,用大括号表示的block\N{\fs12}You know, the curly, curly brace thing, okay?
Dialogue: 0,0:02:56.57,0:02:59.10,yin,,0,0,0,,所以这个队列中都是block\N{\fs12}So you got this queue, in line, you have these blocks,
Dialogue: 0,0:02:59.17,0:03:01.72,yin,,0,0,0,,block排着队等着被执行\N{\fs12}and they're all waiting in line to be executed.
Dialogue: 0,0:03:02.11,0:03:04.26,yin,,0,0,0,,根据所在队列的不同\N{\fs12}And depending on which queue they're in,
Dialogue: 0,0:03:04.40,0:03:06.67,yin,,0,0,0,,当轮到它们 排到了队列前面\N{\fs12}when it's their turn, when they get to the front of the line,
Dialogue: 0,0:03:06.82,0:03:09.69,yin,,0,0,0,,它们会被取出队列 开始执行\N{\fs12}they get taken off the queue and they get to run.
Dialogue: 0,0:03:10.56,0:03:13.08,yin,,0,0,0,,可能是在单独的线程中\N{\fs12}Okay? Possibly in a separate thread.
Dialogue: 0,0:03:13.63,0:03:16.31,yin,,0,0,0,,通常情况下\N{\fs12}Okay? Usually there might be
Dialogue: 0,0:03:16.56,0:03:19.21,yin,,0,0,0,,一个队列会分配单个或多个线程\N{\fs12}multiple threads assigned to one queue, or single thread,
Dialogue: 0,0:03:19.22,0:03:20.65,yin,,0,0,0,,同样的 你并不知道会怎样\N{\fs12}again, you don't know what's going on,
Dialogue: 0,0:03:20.65,0:03:23.13,yin,,0,0,0,,你只知道自己将这些block放入了队列\N{\fs12}all you know is you're putting these blocks in a queue
Dialogue: 0,0:03:23.31,0:03:25.79,yin,,0,0,0,,它们会被取出并运行\N{\fs12}and they are being taken off and allowed to run.
Dialogue: 0,0:03:26.02,0:03:29.70,yin,,0,0,0,,队列允许一次放一个人\N{\fs12}And people can be allowed to come off the queue one at a time,
Dialogue: 0,0:03:29.71,0:03:30.67,yin,,0,0,0,,所以在电影院中\N{\fs12}so at the movie theater,
Dialogue: 0,0:03:30.68,0:03:32.83,yin,,0,0,0,,一个人进去看电影\N{\fs12}one person gets to go and watch the whole movie,
Dialogue: 0,0:03:32.95,0:03:34.87,yin,,0,0,0,,他看完之后 后面那个人再进去\N{\fs12}and when they're done, the next person goes in.
Dialogue: 0,0:03:34.96,0:03:36.93,yin,,0,0,0,,这叫做串行队列\N{\fs12}Okay? That's called a serial queue,
Dialogue: 0,0:03:36.93,0:03:38.97,yin,,0,0,0,,这就是我们要讲的队列\N{\fs12}that's what the queues we're going to talk about are,
Dialogue: 0,0:03:38.97,0:03:39.81,yin,,0,0,0,,是一个非常简单的队列\N{\fs12}it's a very simple queue.
Dialogue: 0,0:03:39.98,0:03:41.48,yin,,0,0,0,,但还有一种并发队列\N{\fs12}There's also concurrent queues, however,
Dialogue: 0,0:03:41.49,0:03:43.23,yin,,0,0,0,,可以让一群人进电影院\N{\fs12}where a whole bunch of people get to go into a theater
Dialogue: 0,0:03:43.24,0:03:46.74,yin,,0,0,0,,可以同时做某事\N{\fs12}and they're all get to be doing stuff simultaneously.
Dialogue: 0,0:03:46.86,0:03:48.19,yin,,0,0,0,,这种略微复杂些\N{\fs12}Okay? It's a little more complicated,
Dialogue: 0,0:03:48.19,0:03:49.92,yin,,0,0,0,,因为你得到这个队列 从中取出block\N{\fs12}because you got this queue, you're pulling off these blocks
Dialogue: 0,0:03:49.92,0:03:51.03,yin,,0,0,0,,它们一起运行\N{\fs12}and they're all running together,
Dialogue: 0,0:03:51.04,0:03:53.87,yin,,0,0,0,,如果它们想要共享资源等等\N{\fs12}if they ever want to share resources or something
Dialogue: 0,0:03:53.89,0:03:55.90,yin,,0,0,0,,需要更高级一些的多线程编程\N{\fs12}they need a little more advanced multithreaded programming
Dialogue: 0,0:03:55.93,0:03:57.21,yin,,0,0,0,,我们要用的是简单的队列\N{\fs12}and we're going to do the simple kind
Dialogue: 0,0:03:57.43,0:03:59.40,yin,,0,0,0,,一次只有一个人从队列中出来\N{\fs12}where one person coming out of the queue,
Dialogue: 0,0:03:59.51,0:04:01.59,yin,,0,0,0,,一次只从队列中取出一个block\N{\fs12}one block coming out of the queue at the same time.
Dialogue: 0,0:04:02.05,0:04:03.72,yin,,0,0,0,,这就是大家要理解的内容\N{\fs12}Okay? So that's really what you understand,
Dialogue: 0,0:04:03.72,0:04:05.31,yin,,0,0,0,,多线程的工作原理就是这样的\N{\fs12}is that's how this multithreading works.
Dialogue: 0,0:04:05.36,0:04:07.15,yin,,0,0,0,,由block组成的队列\N{\fs12}Queues of blocks, okay?
Dialogue: 0,0:04:07.47,0:04:10.62,yin,,0,0,0,,有一个很重要的队列 就是主队列\N{\fs12}Now there's a very important queue, which is the main queue,
Dialogue: 0,0:04:10.62,0:04:13.22,yin,,0,0,0,,在这个队列中处理多点触控\N{\fs12}that's the queue on which multi-touch is happening
Dialogue: 0,0:04:13.22,0:04:15.13,yin,,0,0,0,,以及所有UI操作等等\N{\fs12}and all the UI stuff is happening,
Dialogue: 0,0:04:15.44,0:04:17.16,yin,,0,0,0,,它很特殊 原因有两点\N{\fs12}and this is special for two reasons.
Dialogue: 0,0:04:17.16,0:04:20.58,yin,,0,0,0,,一是我们绝不想让它阻塞\N{\fs12}Alright? One is that we never want to block it, okay?
Dialogue: 0,0:04:20.58,0:04:23.04,yin,,0,0,0,,我们不会将需要执行很长时间的线程\N{\fs12}So we never want to do anything that's gonna take very long
Dialogue: 0,0:04:23.47,0:04:24.89,yin,,0,0,0,,放在主队列上\N{\fs12}on that main queue.
Dialogue: 0,0:04:25.13,0:04:27.55,yin,,0,0,0,,二是我们将其用于同步\N{\fs12}And the second thing is we use it for synchronization
Dialogue: 0,0:04:27.72,0:04:30.96,yin,,0,0,0,,所有UI相关内容的同步\N{\fs12}for everything that is UI related, okay?
Dialogue: 0,0:04:31.12,0:04:34.68,yin,,0,0,0,,全部方法 也不是全部 UIKit中大部分方法\N{\fs12}So all the methods, not all, but most of the methods in UIKit,
Dialogue: 0,0:04:34.93,0:04:36.69,yin,,0,0,0,,只能在主线程中调用它们\N{\fs12}you want to call them only on the main queue,
Dialogue: 0,0:04:36.70,0:04:39.49,yin,,0,0,0,,实际上 如果你在其他block中调用它们\N{\fs12}and in fact, if you call them on some other, some block
Dialogue: 0,0:04:39.68,0:04:41.91,yin,,0,0,0,,从其他队列中取出的block中 可能不会正常运行的\N{\fs12}that came off from some other queue probably wouldn't work.
Dialogue: 0,0:04:42.33,0:04:46.21,yin,,0,0,0,,而有一些对象 比如UIImage UIFont UIColor\N{\fs12}Now there's a few, like UIImage, UIFont, UIColor,
Dialogue: 0,0:04:46.39,0:04:49.47,yin,,0,0,0,,它们不在主线程上一样可以正常运行\N{\fs12}a couple of those things, they'll work off the main queue,
Dialogue: 0,0:04:49.58,0:04:53.02,yin,,0,0,0,,但任何能够或可能引起\N{\fs12}but anything that is going to cause the screen to have to change
Dialogue: 0,0:04:53.03,0:04:56.32,yin,,0,0,0,,屏幕改变或同步等的操作\N{\fs12}or synchronize or anything like that, or that might cause that,
Dialogue: 0,0:04:56.48,0:04:57.90,yin,,0,0,0,,都要发生在主队列上\N{\fs12}that all needs to happen on the main queue,
Dialogue: 0,0:04:57.92,0:04:59.00,yin,,0,0,0,,所以我们要用主队列\N{\fs12}so we use that main queue,
Dialogue: 0,0:04:59.16,0:05:02.09,yin,,0,0,0,,不断响应用户操作\N{\fs12}both to have something that's constantly responsive to the user
Dialogue: 0,0:05:02.10,0:05:03.26,yin,,0,0,0,,和进行同步\N{\fs12}and for synchronization,
Dialogue: 0,0:05:03.26,0:05:06.25,yin,,0,0,0,,让一切和UI同步\N{\fs12}to keep everything in sync of what's going on in the UI side.
Dialogue: 0,0:05:06.42,0:05:08.64,yin,,0,0,0,,其他操作可以放在其他队列中执行\N{\fs12}Everything else we could do in other queues,
Dialogue: 0,0:05:08.65,0:05:10.05,yin,,0,0,0,,实际上 令人惊讶的是\N{\fs12}and actually, amazingly,
Dialogue: 0,0:05:10.06,0:05:13.78,yin,,0,0,0,,iOS会在其他队列中执行绘制等操作\N{\fs12}iOS is doing things like actually drawing in another queue.
Dialogue: 0,0:05:14.13,0:05:16.25,yin,,0,0,0,,你并不知道 不知道是什么队列\N{\fs12}Okay, you don't know that, you don't know what queue it is,
Dialogue: 0,0:05:16.25,0:05:18.38,yin,,0,0,0,,你看不到 但实际上是在其他队列中执行的\N{\fs12}you don't see it, but it's actually doing the other queue,
Dialogue: 0,0:05:18.38,0:05:18.97,yin,,0,0,0,,为什么呢\N{\fs12}why?
Dialogue: 0,0:05:19.08,0:05:21.16,yin,,0,0,0,,因为如果绘制某些复杂图形时\N{\fs12}Because if it's drawing something very graphic-intensive
Dialogue: 0,0:05:21.16,0:05:23.21,yin,,0,0,0,,用户在主队列中用了多点触控\N{\fs12}and the user multi-touches in the main queue,
Dialogue: 0,0:05:23.41,0:05:24.91,yin,,0,0,0,,就要切换回主队列\N{\fs12}you want to switch back to that main queue
Dialogue: 0,0:05:24.92,0:05:27.10,yin,,0,0,0,,赋予优先级\N{\fs12}and give it the, the priority
Dialogue: 0,0:05:27.11,0:05:31.26,yin,,0,0,0,,先完成多点触控 绘制稍后执行\N{\fs12}and the drawing can wait a little bit while that multi-touch gets done.
Dialogue: 0,0:05:32.92,0:05:35.43,yin,,0,0,0,,所以不要阻塞主队列\N{\fs12}Okay? So this main queue doesn't want to be blocked,
Dialogue: 0,0:05:35.43,0:05:36.94,yin,,0,0,0,,我们用主队列来进行同步\N{\fs12}it's where we do the synchronization,
Dialogue: 0,0:05:37.04,0:05:40.40,yin,,0,0,0,,我会演示 如何编写代码\N{\fs12}and I'm gonna show you how you can write code
Dialogue: 0,0:05:40.41,0:05:43.37,yin,,0,0,0,,让它运行在其他队列中 但还要更新UI\N{\fs12}that is running on other queues, but needs to do UI,
Dialogue: 0,0:05:43.61,0:05:44.60,yin,,0,0,0,,因为这是个问题对吧\N{\fs12}because that's a problem, right?
Dialogue: 0,0:05:44.60,0:05:47.20,yin,,0,0,0,,如果在其他队列上有block\N{\fs12}If your got a block that's on another queue,
Dialogue: 0,0:05:47.20,0:05:51.08,yin,,0,0,0,,不在主队列上\N{\fs12}non-main thread queue, non-main queue,
Dialogue: 0,0:05:51.13,0:05:52.41,yin,,0,0,0,,然后还要对UI进行操作\N{\fs12}then, and you want to do some UI,
Dialogue: 0,0:05:52.42,0:05:54.07,yin,,0,0,0,,就必须向主队列通信\N{\fs12}you got to somehow talk to that main queue,
Dialogue: 0,0:05:54.07,0:05:56.50,yin,,0,0,0,,要在主队列上放一个block\N{\fs12}you got put a block, basically, on that main queue.
Dialogue: 0,0:05:57.24,0:05:58.40,yin,,0,0,0,,还有其他队列\N{\fs12}There are other queues,
Dialogue: 0,0:05:58.41,0:06:00.68,yin,,0,0,0,,大部分都是iOS在后台创建的\N{\fs12}mostly they're created by iOS behind the scenes,
Dialogue: 0,0:06:00.68,0:06:02.97,yin,,0,0,0,,幻灯片中有个示例\N{\fs12}I'm going to show you an example here in the slides
Dialogue: 0,0:06:03.09,0:06:06.78,yin,,0,0,0,,会介绍一个API中可以看到的队列\N{\fs12}of a queue that is visible to you in the API
Dialogue: 0,0:06:06.90,0:06:08.13,yin,,0,0,0,,以及我们处理的方法\N{\fs12}and how we deal with that.
Dialogue: 0,0:06:08.97,0:06:11.84,yin,,0,0,0,,那么如何在其他队列上执行block呢\N{\fs12}Alright, so how do you execute a block on another queue?
Dialogue: 0,0:06:12.13,0:06:16.19,yin,,0,0,0,,这是C层API 非常底层的API\N{\fs12}Okay? This is a C-level API, it's a very low-level API,
Dialogue: 0,0:06:16.19,0:06:19.02,yin,,0,0,0,,在对象之下 所以在最底这层API中\N{\fs12}below object, so you're not going to see any object stuff
Dialogue: 0,0:06:19.42,0:06:21.10,yin,,0,0,0,,不会看到任何对象内容\N{\fs12}in this lowest level API.
Dialogue: 0,0:06:21.10,0:06:23.16,yin,,0,0,0,,在这层之上 有一个面向对象层\N{\fs12}There is an object-oriented layer on top of it
Dialogue: 0,0:06:23.17,0:06:25.74,yin,,0,0,0,,叫NSOperationQueue\N{\fs12}called NSOperation, NSOperationQueue,
Dialogue: 0,0:06:26.31,0:06:28.07,yin,,0,0,0,,但那是内容很少的面向对象层\N{\fs12}but it's kind of a thin object-oriented layer.
Dialogue: 0,0:06:28.07,0:06:29.49,yin,,0,0,0,,这是核心层\N{\fs12}This is the core layer.
Dialogue: 0,0:06:29.84,0:06:33.23,yin,,0,0,0,,这是最基本的方法\N{\fs12}And this is the fundamental method, dis, or, sorry,
Dialogue: 0,0:06:33.23,0:06:36.34,yin,,0,0,0,,基本的C函数 dispatch_async\N{\fs12}this is fundamental C function, dispatch, underbar, async,
Dialogue: 0,0:06:36.75,0:06:39.95,yin,,0,0,0,,表示将这个block以异步方式\N{\fs12}and that means asynchronously put this block
Dialogue: 0,0:06:40.23,0:06:41.97,yin,,0,0,0,,放入这个队列中\N{\fs12}on this queue, okay?
Dialogue: 0,0:06:42.32,0:06:44.79,yin,,0,0,0,,可以看到 我声明了一个队列 局部变量queue\N{\fs12}So you see I've declared a queue there, local variable queue,
Dialogue: 0,0:06:44.79,0:06:47.73,yin,,0,0,0,,是dispatch_queue_t类型的 是个typedef\N{\fs12}it's a of type dispatch queue t, which is a typedef,
Dialogue: 0,0:06:48.15,0:06:50.70,yin,,0,0,0,,我稍后会介绍如何获取队列\N{\fs12}and I'll, I'll talk about how to get a queue in a second.
Dialogue: 0,0:06:50.84,0:06:52.55,yin,,0,0,0,,然后用dispatch_async\N{\fs12}And then you just say dispatch async,
Dialogue: 0,0:06:52.58,0:06:55.05,yin,,0,0,0,,然后是目标队列和将要加入队列的block\N{\fs12}the queue you want to put the block on and then the block.
Dialogue: 0,0:06:55.05,0:06:57.46,yin,,0,0,0,,block没有参数 无返回值\N{\fs12}And the block takes no arguments and it returns no values,
Dialogue: 0,0:06:57.46,0:07:00.62,yin,,0,0,0,,只是一个block 可以随意加入代码\N{\fs12}it's just a block, and you can put any code you want in there,
Dialogue: 0,0:07:00.82,0:07:03.87,yin,,0,0,0,,block会在队列中找到位置\N{\fs12}and that block will take its place in line on that queue,
Dialogue: 0,0:07:03.87,0:07:06.74,yin,,0,0,0,,队列排到它时 它就会被取出执行\N{\fs12}and when that queue gets around it, it will take it off.
Dialogue: 0,0:07:06.82,0:07:08.38,yin,,0,0,0,,关于主队列 还有一件事\N{\fs12}One thing, by the way, about the main queue,
Dialogue: 0,0:07:08.47,0:07:12.06,yin,,0,0,0,,它只在安静时才会执行队列中的内容\N{\fs12}it never takes anything out of its queue to run until its quiet,
Dialogue: 0,0:07:12.30,0:07:14.45,yin,,0,0,0,,安静指的是当前没有触控事件\N{\fs12}meaning whatever current touch events
Dialogue: 0,0:07:14.51,0:07:15.83,yin,,0,0,0,,正在被处理\N{\fs12}have been processed, okay?
Dialogue: 0,0:07:15.84,0:07:17.69,yin,,0,0,0,,它不会在处理触控事件时\N{\fs12}It's not going to right in the middle of a touch event
Dialogue: 0,0:07:17.76,0:07:18.95,yin,,0,0,0,,从队列中获取某个block\N{\fs12}take something off its queue
Dialogue: 0,0:07:18.95,0:07:19.99,yin,,0,0,0,,然后去执行它\N{\fs12}and go do something, right?
Dialogue: 0,0:07:20.29,0:07:23.41,yin,,0,0,0,,主队列会等到安静一些时\N{\fs12}So the main queue waits till its a little quieter
Dialogue: 0,0:07:23.41,0:07:25.12,yin,,0,0,0,,再从队列中获取操作并执行\N{\fs12}and then it'll take things off the queue and run it,
Dialogue: 0,0:07:25.17,0:07:27.56,yin,,0,0,0,,所以你可以向主队列中增加任意操作\N{\fs12}so you can always post things on the main queue
Dialogue: 0,0:07:27.57,0:07:30.25,yin,,0,0,0,,肯定不会打断用户操作\N{\fs12}and be sure that it's not gonna interrupt the user in anyway.
Dialogue: 0,0:07:31.35,0:07:33.83,yin,,0,0,0,,那么我们如何获取一个队列\N{\fs12}Alright, so how do we get a queue to send this,
Dialogue: 0,0:07:33.83,0:07:35.34,yin,,0,0,0,,来执行这个dispatch_async呢\N{\fs12}to do this dispatch async with?
Dialogue: 0,0:07:35.65,0:07:37.18,yin,,0,0,0,,先来讲讲如何获取主队列\N{\fs12}Well, let's talk about the main queue first
Dialogue: 0,0:07:37.18,0:07:38.56,yin,,0,0,0,,因为要分派操作\N{\fs12}because that's the most important queue
Dialogue: 0,0:07:38.69,0:07:40.19,yin,,0,0,0,,它是最重要的队列\N{\fs12}that we need to dispatch things,
Dialogue: 0,0:07:40.29,0:07:41.21,yin,,0,0,0,,方法是\N{\fs12}and the way you do that
Dialogue: 0,0:07:41.22,0:07:43.97,yin,,0,0,0,,dispatch_get_main_queue\N{\fs12}is dispatch underbar get, underbar main, underbar queue,
Dialogue: 0,0:07:43.97,0:07:45.69,yin,,0,0,0,,这个方法会返回主队列\N{\fs12}that will return the main queue to you
Dialogue: 0,0:07:45.95,0:07:49.36,yin,,0,0,0,,然后可以对它调用带block参数的dispatch_async\N{\fs12}and then you can call dispatch async with a block on that.
Dialogue: 0,0:07:49.56,0:07:52.45,yin,,0,0,0,,在更高的NSOperationQueue层上\N{\fs12}At the higher level, that NSOperationQueue level,
Dialogue: 0,0:07:52.45,0:07:55.28,yin,,0,0,0,,可以使用NSOperationQueue mainQueue 它是个类方法\N{\fs12}you can do NSOperation mainQueue, it's a class method,
Dialogue: 0,0:07:55.34,0:07:57.58,yin,,0,0,0,,会返回NSOperationQueue对象\N{\fs12}it'll return NSOperationQueue object,
Dialogue: 0,0:07:57.58,0:07:58.89,yin,,0,0,0,,代表主队列\N{\fs12}which represents the main queue.
Dialogue: 0,0:07:59.17,0:08:01.08,yin,,0,0,0,,它只是内容很少的面向对象层\N{\fs12}Again, it's just a thin object-oriented layer,
Dialogue: 0,0:08:01.37,0:08:03.72,yin,,0,0,0,,在C层上\N{\fs12}pretty much, on this C layer,
Dialogue: 0,0:08:03.73,0:08:05.97,yin,,0,0,0,,我们会讲到它在API中的使用\N{\fs12}and we'll, we'll see where that comes into the API.
Dialogue: 0,0:08:07.43,0:08:09.06,yin,,0,0,0,,如果想要再创建一个队列呢\N{\fs12}What if you wanted to create another queue.
Dialogue: 0,0:08:09.06,0:08:11.53,yin,,0,0,0,,假设你要执行大型数学运算\N{\fs12}Let's say you're gonna do some big math calculation
Dialogue: 0,0:08:11.53,0:08:13.64,yin,,0,0,0,,或者大型图像处理运算\N{\fs12}or some big image processing calculation
Dialogue: 0,0:08:13.66,0:08:17.01,yin,,0,0,0,,而你不想阻塞主队列 主线程\N{\fs12}you don't want to block the main queue, the main thread,
Dialogue: 0,0:08:17.15,0:08:18.67,yin,,0,0,0,,这时你就可以再创建一个队列\N{\fs12}so you can create another queue.
Dialogue: 0,0:08:18.73,0:08:21.78,yin,,0,0,0,,非常简单 只要用dispatch_queue_create\N{\fs12}Very simple, you just say dispatch underbar queue, underbar create,
Dialogue: 0,0:08:22.14,0:08:25.86,yin,,0,0,0,,这个函数的第一个参数是队列的名称\N{\fs12}and the first argument to that function is the name of the queue
Dialogue: 0,0:08:25.87,0:08:27.80,yin,,0,0,0,,它会出现在调试程序等之中\N{\fs12}and that's like going to show up in the debugger and stuff,
Dialogue: 0,0:08:27.81,0:08:29.26,yin,,0,0,0,,是个内部名称\N{\fs12}so this is kind of an internal name,
Dialogue: 0,0:08:29.51,0:08:31.31,yin,,0,0,0,,注意它不是一个NSString\N{\fs12}notice that's not an NSString,
Dialogue: 0,0:08:31.65,0:08:33.33,yin,,0,0,0,,因为这是底层API\N{\fs12}because this is a low-level API,
Dialogue: 0,0:08:33.39,0:08:35.89,yin,,0,0,0,,这是这门课上\N{\fs12}this is about the only non-NSString string
Dialogue: 0,0:08:35.90,0:08:36.92,yin,,0,0,0,,唯一一处使用非NSString字符串的地方\N{\fs12}you're ever going to see in this class,
Dialogue: 0,0:08:36.93,0:08:38.74,yin,,0,0,0,,因为这是我们用到的最底层\N{\fs12}because this is the lowest level we'll go.
Dialogue: 0,0:08:39.21,0:08:40.76,yin,,0,0,0,,它是个const char\N{\fs12}It's a const char star,
Dialogue: 0,0:08:40.98,0:08:43.28,yin,,0,0,0,,这里我就直接用name了\N{\fs12}and here I'm just using the name name, okay?
Dialogue: 0,0:08:43.30,0:08:45.49,yin,,0,0,0,,命名时要选择好辨认的名字\N{\fs12}You just want to give it a name so you can recognize this queue
Dialogue: 0,0:08:45.49,0:08:47.36,yin,,0,0,0,,方便在调试程序等中认出这个队列\N{\fs12}when you see it in the debugger or something like that.
Dialogue: 0,0:08:47.64,0:08:50.25,yin,,0,0,0,,第二个参数代表它是串行队列\N{\fs12}And then the second argument is whether it's a serial queue
Dialogue: 0,0:08:50.25,0:08:51.96,yin,,0,0,0,,还是并发队列\N{\fs12}or a concurrent queue, right?
Dialogue: 0,0:08:52.19,0:08:54.39,yin,,0,0,0,,NULL代表串行队列\N{\fs12}So, NULL means it's a serial queue,
Dialogue: 0,0:08:54.86,0:08:57.43,yin,,0,0,0,,我们要讲的就是这类队列\N{\fs12}and so, that's the kind of queue we're gonna talk about,
Dialogue: 0,0:08:57.49,0:09:00.24,yin,,0,0,0,,一次从队列中出来一个人\N{\fs12}again, so one person comes out of the line at a time.
Dialogue: 0,0:09:01.16,0:09:03.30,yin,,0,0,0,,对于分派回主队列\N{\fs12}And there's kind of an easy mode
Dialogue: 0,0:09:03.30,0:09:05.36,yin,,0,0,0,,有一个简单模式\N{\fs12}for dispatching back to the main queue,
Dialogue: 0,0:09:05.47,0:09:07.68,yin,,0,0,0,,就是用performSelectorOnMainThread\N{\fs12}which is performSelectorOnMainThread,
Dialogue: 0,0:09:07.69,0:09:09.56,yin,,0,0,0,,它是一个NSObject方法\N{\fs12}it's an NSObject method.
Dialogue: 0,0:09:09.77,0:09:11.15,yin,,0,0,0,,可以将它发给任意NSObject\N{\fs12}You can send it to any NSObject.
Dialogue: 0,0:09:11.38,0:09:14.31,yin,,0,0,0,,只要直接传递一个selector和它的参数\N{\fs12}And you just pass a selector and its argument,
Dialogue: 0,0:09:14.31,0:09:16.47,yin,,0,0,0,,withObject参数 可以为nil\N{\fs12}the withObject argument, it could be nil
Dialogue: 0,0:09:16.47,0:09:18.01,yin,,0,0,0,,代表没有参数 是可以的\N{\fs12}and then it has no arguments, that's fine.
Dialogue: 0,0:09:18.89,0:09:21.23,yin,,0,0,0,,waitUntilDone代表是否要等待\N{\fs12}And the waitUntilDone is whether you're gonna wait
Dialogue: 0,0:09:21.24,0:09:23.29,yin,,0,0,0,,调用它的这个线程执行之后\N{\fs12}until this thing gets pulled off the main queue
Dialogue: 0,0:09:23.30,0:09:25.65,yin,,0,0,0,,再将它从主队列调出\N{\fs12}and run on the main queue and then finishes
Dialogue: 0,0:09:25.66,0:09:29.80,yin,,0,0,0,,并在主队列上运行\N{\fs12}before this thread, that's calling this, goes or not,
Dialogue: 0,0:09:29.82,0:09:32.48,yin,,0,0,0,,waitUntilDone通常设为NO 不需要等待\N{\fs12}usually waitUntilDone you would say no, we don't need to wait,
Dialogue: 0,0:09:32.48,0:09:35.31,yin,,0,0,0,,我们会在主队列上调用这个方法\N{\fs12}we're going to put this, call this method on the main queue,
Dialogue: 0,0:09:35.64,0:09:38.53,yin,,0,0,0,,轮到它执行时就执行\N{\fs12}and whenever it executes is when it executes.
Dialogue: 0,0:09:38.53,0:09:41.12,yin,,0,0,0,,这个performSelectorOnMainThread方法\N{\fs12}So, this performSelectorOnMainThread is just
Dialogue: 0,0:09:41.14,0:09:44.34,yin,,0,0,0,,就相当于对主队列调用dispatch_async\N{\fs12}like saying dispatch async onto the main queue,
Dialogue: 0,0:09:44.61,0:09:46.34,yin,,0,0,0,,一个调用了该方法的block\N{\fs12}a block that just calls that method.
Dialogue: 0,0:09:47.48,0:09:48.87,yin,,0,0,0,,这个方法就是这样\N{\fs12}Okay? That's all it is really,
Dialogue: 0,0:09:49.22,0:09:50.23,yin,,0,0,0,,基本上算是个简易模式\N{\fs12}bascially it's kind of an easy mode,
Dialogue: 0,0:09:50.24,0:09:51.59,yin,,0,0,0,,看起来很好用\N{\fs12}it looks nice, and so, you know,
Dialogue: 0,0:09:51.75,0:09:53.72,yin,,0,0,0,,不用再用dispatch_async方法了\N{\fs12}you don't have to do the dispatch async business,
Dialogue: 0,0:09:54.00,0:09:56.15,yin,,0,0,0,,可以直接调用一个方法\N{\fs12}but you got to be able to have one method to call,
Dialogue: 0,0:09:56.45,0:09:58.54,yin,,0,0,0,,将所有要执行的操作放到一个方法中\N{\fs12}put all the stuff you want to do on one method.
Dialogue: 0,0:10:00.04,0:10:01.73,yin,,0,0,0,,我们看一个使用它的例子\N{\fs12}So let's look at an example that uses this, okay?
Dialogue: 0,0:10:01.77,0:10:04.77,yin,,0,0,0,,通过示例演示 更容易理解\N{\fs12}This is more understandable, probably much more by example.
Dialogue: 0,0:10:04.91,0:10:10.19,yin,,0,0,0,,这个例子是要下载网上某个URL\N{\fs12}So, this example is I want to download the contents of an URL
Dialogue: 0,0:10:10.37,0:10:11.40,yin,,0,0,0,,对应的内容\N{\fs12}from somewhere on the internet.
Dialogue: 0,0:10:11.79,0:10:14.79,yin,,0,0,0,,我有一个URL http://或者其他格式\N{\fs12}So I have a URL, http:// something or other,
Dialogue: 0,0:10:14.98,0:10:16.79,yin,,0,0,0,,我想要将它从网上下载下来\N{\fs12}and I want to download that from the internet.
Dialogue: 0,0:10:16.79,0:10:18.75,yin,,0,0,0,,可能我用的是蜂窝移动网\N{\fs12}Well, I might be on cellular,
Dialogue: 0,0:10:18.77,0:10:21.58,yin,,0,0,0,,甚至目前不在网络范围\N{\fs12}I might even be out of network range right now,
Dialogue: 0,0:10:21.58,0:10:22.98,yin,,0,0,0,,下载会花费很长时间\N{\fs12}that could take a very long time.
Dialogue: 0,0:10:22.98,0:10:24.38,yin,,0,0,0,,可能要几分钟\N{\fs12}It could take minutes, okay,
Dialogue: 0,0:10:24.38,0:10:27.02,yin,,0,0,0,,我当然不希望在等待获取URL内容时\N{\fs12}well clearly I don't want my user interface, for example,
Dialogue: 0,0:10:27.02,0:10:28.90,yin,,0,0,0,,我的用户界面\N{\fs12}to be blocked waiting for the network
Dialogue: 0,0:10:28.96,0:10:30.55,yin,,0,0,0,,被卡主 无法操作\N{\fs12}to give me that URL back. Okay?
Dialogue: 0,0:10:30.57,0:10:34.65,yin,,0,0,0,,所以在调用下载操作时\N{\fs12}So I have to, basically, call this, do this download,
Dialogue: 0,0:10:34.66,0:10:37.14,yin,,0,0,0,,要将网络下载操作放到另一个队列中执行\N{\fs12}network download, in a different queue,
Dialogue: 0,0:10:37.14,0:10:39.48,yin,,0,0,0,,另一个线程 而非主队列\N{\fs12}in a different thread, not the main queue. Okay?
Dialogue: 0,0:10:39.97,0:10:43.44,yin,,0,0,0,,iOS中有一个API可以实现这个操作\N{\fs12}So there's an API in iOS for doing exactly this,
Dialogue: 0,0:10:43.44,0:10:46.25,yin,,0,0,0,,给它一个URL 它就会在另一个线程中执行\N{\fs12}you give it a URL and it will go do it in a different thread.
Dialogue: 0,0:10:46.53,0:10:49.70,yin,,0,0,0,,当它完成时 需要再调用你\N{\fs12}Now, when it's done though, it needs to call you back,
Dialogue: 0,0:10:49.80,0:10:51.72,yin,,0,0,0,,告诉你说 我下好这个URL了\N{\fs12}and tell you hey, I got that URL,
Dialogue: 0,0:10:51.73,0:10:53.26,yin,,0,0,0,,方法很酷\N{\fs12}and the way it does that is kind of cool,
Dialogue: 0,0:10:53.41,0:10:55.92,yin,,0,0,0,,它会将URL内容下载到一个本地文件中\N{\fs12}it downloads the URL to a local file,
Dialogue: 0,0:10:56.12,0:10:57.14,yin,,0,0,0,,然后再调用你\N{\fs12}and then it calls you back
Dialogue: 0,0:10:57.53,0:10:59.44,yin,,0,0,0,,给你一个本地文件的URL\N{\fs12}and gives you a URL to the local file.
Dialogue: 0,0:10:59.60,0:11:00.77,yin,,0,0,0,,这样就变成本地操作了\N{\fs12}So now it's all local,
Dialogue: 0,0:11:00.85,0:11:02.77,yin,,0,0,0,,你可以打开文件做各种操作\N{\fs12}and so now you can open up the file and do all you want
Dialogue: 0,0:11:02.78,0:11:04.07,yin,,0,0,0,,不会阻塞用户界面操作\N{\fs12}and it's not going to be blocking
Dialogue: 0,0:11:04.09,0:11:06.52,yin,,0,0,0,,因为这时不涉及网络因素了\N{\fs12}because you, the network is not a part of it anymore,
Dialogue: 0,0:11:06.52,0:11:08.24,yin,,0,0,0,,已经下载好了URL的内容\N{\fs12}it's download the contents of the URL.
Dialogue: 0,0:11:08.68,0:11:09.93,yin,,0,0,0,,这是它的具体方法\N{\fs12}Okay, so here's how that works.
Dialogue: 0,0:11:10.21,0:11:11.95,yin,,0,0,0,,先创建一个URL请求\N{\fs12}First we create a URL request,
Dialogue: 0,0:11:11.97,0:11:14.21,yin,,0,0,0,,URL请求是URL的封装\N{\fs12}a URL request is just a wrapper on URL,
Dialogue: 0,0:11:14.23,0:11:15.32,yin,,0,0,0,,是这样创建的\N{\fs12}you can see I created there,
Dialogue: 0,0:11:15.34,0:11:19.89,yin,,0,0,0,,requestWithURL:[NSURL urlWithString以及某个URL\N{\fs12}requestWithURL, NSURL, object, urlWithString, some URL.
Dialogue: 0,0:11:19.90,0:11:21.60,yin,,0,0,0,,这就是创建URL请求的方法\N{\fs12}Okay? So that's how we create a URL request.
Dialogue: 0,0:11:21.82,0:11:24.07,yin,,0,0,0,,URL请求比URL功能更多\N{\fs12}A URL request is a little more than URL
Dialogue: 0,0:11:24.09,0:11:26.70,yin,,0,0,0,,你可以为请求指定其他内容\N{\fs12}because you can specify some other things about that request,
Dialogue: 0,0:11:26.70,0:11:27.45,yin,,0,0,0,,其他操作\N{\fs12}things you want to do,
Dialogue: 0,0:11:27.46,0:11:29.34,yin,,0,0,0,,我们通常会直接创建 就像这里一样\N{\fs12}and most of the time we just create it, just like this,
Dialogue: 0,0:11:29.35,0:11:30.68,yin,,0,0,0,,请求没有其他内容了\N{\fs12}and we don't do anything else to the request.
Dialogue: 0,0:11:30.68,0:11:35.91,yin,,0,0,0,,现在我们得到了一个URL请求\N{\fs12}So now we have a request, a URL, a URL request, and,
Dialogue: 0,0:11:35.91,0:11:38.97,yin,,0,0,0,,抱歉 我发不好URL这个音\N{\fs12}I apologize in advance for URL, I have trouble saying that,
Dialogue: 0,0:11:38.97,0:11:41.34,yin,,0,0,0,,后面我要说好多遍\N{\fs12}I'm gonna be saying that 100 times in the next few slides.
Dialogue: 0,0:11:42.19,0:11:43.81,yin,,0,0,0,,然后是Configuration配置部分\N{\fs12}Then we have this configuration thing,
Dialogue: 0,0:11:43.81,0:11:45.22,yin,,0,0,0,,现在不用担心这部分\N{\fs12}don't worry about that for now.
Dialogue: 0,0:11:45.65,0:11:48.74,yin,,0,0,0,,然后创建的是URLSession会话\N{\fs12}And then we have, we create what's called a URLSession.
Dialogue: 0,0:11:49.06,0:11:54.31,yin,,0,0,0,,URLSession是一个对象 用来管理一个会话的时间\N{\fs12}So URLSession is an object that manages a session of time
Dialogue: 0,0:11:54.43,0:11:55.82,yin,,0,0,0,,开始与网络通信\N{\fs12}that goes out and talks to the internet
Dialogue: 0,0:11:55.83,0:11:57.20,yin,,0,0,0,,得到答案等等\N{\fs12}and gets the answer and all this stuff,
Dialogue: 0,0:11:57.21,0:11:59.25,yin,,0,0,0,,session会话就是这里要做的主要内容\N{\fs12}so the session is the main thing that it's doing here
Dialogue: 0,0:11:59.26,0:12:00.93,yin,,0,0,0,,我们会讲讲创建的方法\N{\fs12}and we're going to talk about how we create that,
Dialogue: 0,0:12:00.93,0:12:05.04,yin,,0,0,0,,因为创建NSURLSession的方法\N{\fs12}because how we create the NSURLSession determines where,
Dialogue: 0,0:12:05.17,0:12:09.61,yin,,0,0,0,,决定了代码会在哪个线程队列上执行\N{\fs12}what thread, which queue, our code is gonna be executed on,
Dialogue: 0,0:12:10.01,0:12:12.94,yin,,0,0,0,,现在我们创建了session 我们可以请求它\N{\fs12}and so now we have a session and we can ask the session,
Dialogue: 0,0:12:12.94,0:12:16.53,yin,,0,0,0,,请创建一个任务 下载该URL\N{\fs12}please create us a task which downloads that URL,
Dialogue: 0,0:12:16.88,0:12:19.58,yin,,0,0,0,,非常简单 就用downloadTaskWithRequest方法\N{\fs12}very simple downloadTaskWithRequest,
Dialogue: 0,0:12:19.74,0:12:20.90,yin,,0,0,0,,给它一个URL请求\N{\fs12}you give it the URLRequest,
Dialogue: 0,0:12:21.16,0:12:22.95,yin,,0,0,0,,然后是一个完成处理程序completionHandler\N{\fs12}and then you give it a completionHandler.
Dialogue: 0,0:12:23.15,0:12:25.26,yin,,0,0,0,,理解这个completionHandler很重要\N{\fs12}Now that completion handler very important to understand,
Dialogue: 0,0:12:25.26,0:12:27.49,yin,,0,0,0,,可以看到 它是一个block 对吧\N{\fs12}you can see that it's a block. Right?
Dialogue: 0,0:12:27.82,0:12:29.29,yin,,0,0,0,,block的参数\N{\fs12}The arguments to that block,
Dialogue: 0,0:12:29.39,0:12:31.20,yin,,0,0,0,,第一个参数最重要\N{\fs12}the first argument is the most important argument,
Dialogue: 0,0:12:31.39,0:12:33.87,yin,,0,0,0,,是本地文件URL\N{\fs12}that's the URL of the local file
Dialogue: 0,0:12:33.87,0:12:35.56,yin,,0,0,0,,网络URL的保存地址\N{\fs12}that it put the URL into for you.
Dialogue: 0,0:12:36.14,0:12:38.32,yin,,0,0,0,,它将URL内容从网上下载下来\N{\fs12}So it downloaded this URL off your internet
Dialogue: 0,0:12:38.33,0:12:41.44,yin,,0,0,0,,保存在本地文件中 再返回文件URL\N{\fs12}and it put it in a local file and now it's giving you a file URL,
Dialogue: 0,0:12:41.44,0:12:45.19,yin,,0,0,0,,不是http:// 而是file:文件URL\N{\fs12}not an http// URL, but a file, colon, URL, right?
Dialogue: 0,0:12:45.20,0:12:46.74,yin,,0,0,0,,指向本地文件的URL\N{\fs12}URL that points to a local file.
Dialogue: 0,0:12:47.00,0:12:49.58,yin,,0,0,0,,还有错误和响应参数\N{\fs12}And then the other arguments are about errors and responses,
Dialogue: 0,0:12:49.58,0:12:50.29,yin,,0,0,0,,不用担心\N{\fs12}don't worry about those,
Dialogue: 0,0:12:50.30,0:12:52.77,yin,,0,0,0,,主要就是得到这个本地文件\N{\fs12}the main thing is you got this local file.
Dialogue: 0,0:12:53.01,0:12:55.29,yin,,0,0,0,,然后 在block中\N{\fs12}And then inside this block, okay,
Dialogue: 0,0:12:55.85,0:12:59.19,yin,,0,0,0,,如果要在这里做UI操作呢\N{\fs12}what if you wanted to do UI things here? Okay?
Dialogue: 0,0:12:59.68,0:13:03.61,yin,,0,0,0,,如果这个block是在主队列上被执行的\N{\fs12}Well, if this block is being executed on the main queue,
Dialogue: 0,0:13:03.79,0:13:04.66,yin,,0,0,0,,你就可以这样做\N{\fs12}you're good to go.
Dialogue: 0,0:13:05.14,0:13:06.92,yin,,0,0,0,,但如果是在其他队列上执行的\N{\fs12}But if it's being executed on some other queue,
Dialogue: 0,0:13:06.92,0:13:08.75,yin,,0,0,0,,都不能这样做\N{\fs12}any other queue, you're not good to go,
Dialogue: 0,0:13:08.76,0:13:11.11,yin,,0,0,0,,需要向主队列通信\N{\fs12}you're gonna have to talk back to the main queue.
Dialogue: 0,0:13:11.28,0:13:12.78,yin,,0,0,0,,我们来看一下这两个示例\N{\fs12}So let's look at those two examples.
Dialogue: 0,0:13:13.03,0:13:15.19,yin,,0,0,0,,先看一下session会话的创建方法\N{\fs12}First of all, let's look at creating the session
Dialogue: 0,0:13:15.85,0:13:19.16,yin,,0,0,0,,用这个方法 sessionWithConfiguration\N{\fs12}using this method, sessionWithConfiguration,
Dialogue: 0,0:13:19.16,0:13:20.42,yin,,0,0,0,,这里也不用考虑配置部分\N{\fs12}again, don't worry about configuration,
Dialogue: 0,0:13:20.60,0:13:24.87,yin,,0,0,0,,delegate:nil delegateQueue:某个队列\N{\fs12}delegate, colon, nil, delegateQueue, colon, some queue.
Dialogue: 0,0:13:25.55,0:13:29.60,yin,,0,0,0,,这个NSURLSession有一个委托\N{\fs12}Okay? So this NSURLSession thing, it has a delegate.
Dialogue: 0,0:13:29.60,0:13:32.53,yin,,0,0,0,,还记得委托吗 我们逐渐熟悉了委托\N{\fs12}Remember delegates, we're just getting used to delegates now,
Dialogue: 0,0:13:32.53,0:13:35.87,yin,,0,0,0,,希望大家还记得我们用过的动力动画者委托\N{\fs12}hopefully you are, remember the dynamic animator delegate that we set
Dialogue: 0,0:13:36.01,0:13:38.80,yin,,0,0,0,,它可以告诉我们动画在何时停止\N{\fs12}and it told us when all the animation stopped
Dialogue: 0,0:13:38.81,0:13:40.90,yin,,0,0,0,,然后将方块炸飞\N{\fs12}and then we blew up the blocks? Okay?
Dialogue: 0,0:13:40.93,0:13:44.74,yin,,0,0,0,,我们将动画者的一个委托设为控制器\N{\fs12}So we just set a delegate of the animator to be the controller
Dialogue: 0,0:13:44.77,0:13:46.07,yin,,0,0,0,,控制器实现方法\N{\fs12}and the controller implemented the method.
Dialogue: 0,0:13:46.07,0:13:46.83,yin,,0,0,0,,这里也是一样\N{\fs12}Same thing here.
Dialogue: 0,0:13:46.98,0:13:50.10,yin,,0,0,0,,你可以将自己设为这个URLSession的委托\N{\fs12}You can set yourself as a delegate to this URLSession,
Dialogue: 0,0:13:50.22,0:13:51.89,yin,,0,0,0,,在进行下载时\N{\fs12}and as its doing all its downloading,
Dialogue: 0,0:13:51.98,0:13:54.82,yin,,0,0,0,,它会向你更新状态 我下载了5000字节\N{\fs12}it'll give you updates, oh, I loaded it at 5,000 bytes,
Dialogue: 0,0:13:54.82,0:13:57.87,yin,,0,0,0,,又下载了一些 现在下好了文件\N{\fs12}I just loaded some more bytes, oh, I've got the file now.
Dialogue: 0,0:13:57.87,0:14:00.30,yin,,0,0,0,,我将它保存在了本地磁盘的一个文件中\N{\fs12}Okay, I'm putting it into a file, a local disc,
Dialogue: 0,0:14:00.30,0:14:01.49,yin,,0,0,0,,它会告诉你这些消息\N{\fs12}it'll tell you all these things.
Dialogue: 0,0:14:01.73,0:14:03.13,yin,,0,0,0,,你通常不会在意这些内容\N{\fs12}Usually you don't care about any of that,
Dialogue: 0,0:14:03.14,0:14:04.82,yin,,0,0,0,,只需要它告诉你什么时候完成了\N{\fs12}you just want it to tell you when you're done,
Dialogue: 0,0:14:04.83,0:14:06.52,yin,,0,0,0,,也就是completionHandler的作用\N{\fs12}which is what that completion handler is for.
Dialogue: 0,0:14:06.83,0:14:08.55,yin,,0,0,0,,这里我要将委托delegate设为nil\N{\fs12}So here I'm going to set my delegate to nil.
Dialogue: 0,0:14:08.81,0:14:10.67,yin,,0,0,0,,我不想得到这些杂乱的消息\N{\fs12}I don't even want to hear any of that mess,
Dialogue: 0,0:14:10.67,0:14:12.95,yin,,0,0,0,,我只希望我的完成处理程序\N{\fs12}I just want my completion handler
Dialogue: 0,0:14:13.49,0:14:14.96,yin,,0,0,0,,中间的这个 被调用\N{\fs12}that you see here, called.
Dialogue: 0,0:14:15.56,0:14:18.27,yin,,0,0,0,,而delegateQueue\N{\fs12}But, the delegateQueue, okay,
Dialogue: 0,0:14:18.27,0:14:21.61,yin,,0,0,0,,代表你所有的委托方法\N{\fs12}tells you which queue are all your delegate methods
Dialogue: 0,0:14:21.62,0:14:24.11,yin,,0,0,0,,会在哪个队列上被调用\N{\fs12}going to be called on, okay?
Dialogue: 0,0:14:24.31,0:14:26.60,yin,,0,0,0,,可以指定为主队列 这里就是\N{\fs12}And you can specify the main queue, as we have here,
Dialogue: 0,0:14:26.60,0:14:28.18,yin,,0,0,0,,还可以指定其他队列\N{\fs12}or you can specify some other queue.
Dialogue: 0,0:14:29.15,0:14:31.32,yin,,0,0,0,,这里还可以用nil\N{\fs12}Okay? You can even pass nil here
Dialogue: 0,0:14:31.33,0:14:33.47,yin,,0,0,0,,它会为你随机分配一个队列\N{\fs12}and it'll just make up a queue for you, a random queue.
Dialogue: 0,0:14:34.14,0:14:36.34,yin,,0,0,0,,所以即便这里没有使用委托方法\N{\fs12}So even though we're not doing delegate methods here,
Dialogue: 0,0:14:36.34,0:14:38.05,yin,,0,0,0,,也有完成处理程序\N{\fs12}we are having that completion handler,
Dialogue: 0,0:14:38.05,0:14:39.70,yin,,0,0,0,,它会在委托的那个队列上\N{\fs12}and it calls your completion handler
Dialogue: 0,0:14:39.70,0:14:41.41,yin,,0,0,0,,调用完成处理程序\N{\fs12}on the same queue as the delegates.
Dialogue: 0,0:14:41.49,0:14:43.53,yin,,0,0,0,,所以delegateQueue这行代码\N{\fs12}So that's why that delegateQueue line there
Dialogue: 0,0:14:43.54,0:14:44.34,yin,,0,0,0,,非常重要\N{\fs12}is really important.
Dialogue: 0,0:14:44.61,0:14:47.13,yin,,0,0,0,,这行代码表示调用我的完成处理程序\N{\fs12}What that says is call my completion handler,
Dialogue: 0,0:14:47.18,0:14:48.85,yin,,0,0,0,,如果有委托方法 同样调用\N{\fs12}and all my delegate methods if I had them,
Dialogue: 0,0:14:49.17,0:14:51.61,yin,,0,0,0,,在这个队列上调用我的完成处理程序\N{\fs12}call my completion handler on this queue,
Dialogue: 0,0:14:51.61,0:14:53.45,yin,,0,0,0,,我指定了主队列\N{\fs12}and I've specified the main queue.
Dialogue: 0,0:14:53.81,0:14:55.05,yin,,0,0,0,,代表下面这里\N{\fs12}So that means the code
Dialogue: 0,0:14:55.07,0:14:57.81,yin,,0,0,0,,completionHandler中的代码\N{\fs12}that's inside my completion handler block down there,
Dialogue: 0,0:14:57.89,0:15:00.96,yin,,0,0,0,,黄色部分 写着可以直接做UI操作\N{\fs12}the part in yellow that says yes, can do UI things directly,
Dialogue: 0,0:15:01.23,0:15:02.96,yin,,0,0,0,,这段代码会在主队列上被执行\N{\fs12}that's being executed on the main queue.
Dialogue: 0,0:15:02.96,0:15:05.06,yin,,0,0,0,,它会被放到主队列的待运行队列上\N{\fs12}It gets put in line to run on the main queue,
Dialogue: 0,0:15:05.06,0:15:06.20,yin,,0,0,0,,主队列无操作时\N{\fs12}and when the main queue is quiet,
Dialogue: 0,0:15:06.58,0:15:07.97,yin,,0,0,0,,会抓取这段代码并执行它\N{\fs12}it'll grab it and execute it.
Dialogue: 0,0:15:08.21,0:15:10.33,yin,,0,0,0,,所以我可以在这里做任意UI操作\N{\fs12}So I can do whatever I want UI-wise in here.
Dialogue: 0,0:15:10.33,0:15:11.27,yin,,0,0,0,,因为我在主队列中\N{\fs12}I'm on the main queue.
Dialogue: 0,0:15:11.54,0:15:14.28,yin,,0,0,0,,反过来说 不要在这里做开销大的操作\N{\fs12}Now, conversely, I wouldn't want to do anything expensive here,
Dialogue: 0,0:15:14.28,0:15:16.70,yin,,0,0,0,,比如查看和解析URL\N{\fs12}like, look in the URL and parse it
Dialogue: 0,0:15:16.70,0:15:19.09,yin,,0,0,0,,构建大型数据结构等等\N{\fs12}and build some huge data structure and all this stuff,
Dialogue: 0,0:15:19.09,0:15:21.09,yin,,0,0,0,,有可能会阻塞主队列的操作\N{\fs12}something that might block the main queue, right?
Dialogue: 0,0:15:21.22,0:15:22.72,yin,,0,0,0,,会花费很长时间\N{\fs12}By being, taking a long time.
Dialogue: 0,0:15:23.01,0:15:25.97,yin,,0,0,0,,真的会花费很长时间\N{\fs12}I mean, it would have to really take a long time, but, you know,
Dialogue: 0,0:15:26.19,0:15:27.13,yin,,0,0,0,,你肯定不想在那个block中\N{\fs12}or you certainly wouldn't want
Dialogue: 0,0:15:27.14,0:15:29.89,yin,,0,0,0,,再增加一个网络调用\N{\fs12}to make another network call in that block, okay?
Dialogue: 0,0:15:31.22,0:15:33.14,yin,,0,0,0,,但最重要的是\N{\fs12}But, mostly, most importantly,
Dialogue: 0,0:15:33.15,0:15:35.05,yin,,0,0,0,,可以在这里使用UI调用\N{\fs12}I can make UI calls here, I could update,
Dialogue: 0,0:15:35.05,0:15:38.27,yin,,0,0,0,,如果这是个图片URL 我可以更新UI显示出来\N{\fs12}if this was an image URL, I could update my UI to show the image
Dialogue: 0,0:15:38.27,0:15:39.29,yin,,0,0,0,,或者其他操作\N{\fs12}or whatever I want it to do.
Dialogue: 0,0:15:39.57,0:15:41.89,yin,,0,0,0,,因为我已经指定了它会在主队列上执行\N{\fs12}Because I've specified that it's gonna run in the main queue.
Dialogue: 0,0:15:43.08,0:15:43.73,yin,,0,0,0,,有问题吗\N{\fs12}Okay? Question?
Dialogue: 0,0:15:45.52,0:15:49.71,yin,,0,0,0,,学生提问\N{\fs12}Student:[inaudible]
Dialogue: 0,0:15:49.71,0:15:51.96,yin,,0,0,0,,问题是 队列是否会\N{\fs12}The question is does a queue finish a block
Dialogue: 0,0:15:51.98,0:15:53.76,yin,,0,0,0,,先完成队列中的一个block\N{\fs12}that it takes out of the queue first
Dialogue: 0,0:15:53.77,0:15:55.05,yin,,0,0,0,,然后再抓取下一个\N{\fs12}before it grabs another one?
Dialogue: 0,0:15:55.30,0:15:56.85,yin,,0,0,0,,是的 串行队列是这样的\N{\fs12}Yes. If it's a serial queue,
Dialogue: 0,0:15:56.86,0:15:58.38,yin,,0,0,0,,我们讲的就是这种队列\N{\fs12}which is the kind of queues we're talking about.
Dialogue: 0,0:15:58.71,0:16:00.92,yin,,0,0,0,,会连续地按照顺序执行\N{\fs12}Yes. It, it does them in order, serially.
Dialogue: 0,0:16:02.69,0:16:05.30,yin,,0,0,0,,我们来看另一个例子\N{\fs12}Okay. So now let's look at a different case.
Dialogue: 0,0:16:05.45,0:16:07.45,yin,,0,0,0,,如果创建NSURLSession时\N{\fs12}What if we created NSURLSession
Dialogue: 0,0:16:07.65,0:16:09.58,yin,,0,0,0,,不指定委托队列delegateQueue呢\N{\fs12}that does not specify the delegateQueue?
Dialogue: 0,0:16:09.69,0:16:12.63,yin,,0,0,0,,直接用NSURLSession sessionWithConfiguration\N{\fs12}So I just use NSURLSession, sessionWithConfiguration,
Dialogue: 0,0:16:12.91,0:16:15.22,yin,,0,0,0,,没有delegat或delegateQueue参数\N{\fs12}no delegate, or delegateQueue argument there.
Dialogue: 0,0:16:15.63,0:16:17.82,yin,,0,0,0,,这个例子不用主队列\N{\fs12}This case does not use the main queue,
Dialogue: 0,0:16:17.82,0:16:18.95,yin,,0,0,0,,而是另外一个队列\N{\fs12}it uses a different queue.
Dialogue: 0,0:16:19.37,0:16:20.58,yin,,0,0,0,,没有委托\N{\fs12}Okay? There's no delegate,
Dialogue: 0,0:16:20.80,0:16:25.58,yin,,0,0,0,,所以也不用指定委托方法\N{\fs12}so, there's no need to have the delegate method specified.
Dialogue: 0,0:16:25.78,0:16:28.88,yin,,0,0,0,,但回调函数 这个completionHandler\N{\fs12}But, the callback, okay, this completion handler
Dialogue: 0,0:16:29.03,0:16:32.15,yin,,0,0,0,,会在另一个队列上执行 而不是主队列\N{\fs12}gets executed on a different queue, not on the main queue.
Dialogue: 0,0:16:32.53,0:16:34.03,yin,,0,0,0,,因为我没有指定主队列\N{\fs12}Okay? Because I haven't specified the main queue
Dialogue: 0,0:16:34.03,0:16:35.54,yin,,0,0,0,,为其所在执行队列\N{\fs12}as the queue I want it to execute on.
Dialogue: 0,0:16:36.07,0:16:38.55,yin,,0,0,0,,所以在这个例子中 如果我要做UI操作\N{\fs12}So in this case, if I want to do UI stuff,
Dialogue: 0,0:16:39.06,0:16:42.82,yin,,0,0,0,,需要再增加一个block\N{\fs12}I have to make another block of stuff
Dialogue: 0,0:16:42.97,0:16:45.03,yin,,0,0,0,,将其放到主队列上\N{\fs12}and put it onto the main queue.
Dialogue: 0,0:16:45.70,0:16:47.87,yin,,0,0,0,,我可以用dispatch_async\N{\fs12}And I can do that either with dispatch async,
Dialogue: 0,0:16:47.94,0:16:50.43,yin,,0,0,0,,dispatch_get_main_queue 加一个block\N{\fs12}dispatch_get_main_queue, a block,
Dialogue: 0,0:16:50.55,0:16:52.60,yin,,0,0,0,,里面是要做的UI操作\N{\fs12}with this stuff, UI stuff I want to do,
Dialogue: 0,0:16:52.79,0:16:55.43,yin,,0,0,0,,或者用self performSelectorOnMainThread\N{\fs12}or I could do self performSelectorOnMainThread
Dialogue: 0,0:16:55.59,0:16:57.67,yin,,0,0,0,,加上主队列上的方法\N{\fs12}with some method on the main queue,
Dialogue: 0,0:16:57.97,0:17:00.18,yin,,0,0,0,,或者是要执行的方法\N{\fs12}or method that I want to execute,
Dialogue: 0,0:17:00.18,0:17:01.72,yin,,0,0,0,,它就会在主队列上被调用\N{\fs12}and it'll be called on the main queue.
Dialogue: 0,0:17:02.56,0:17:05.42,yin,,0,0,0,,知道为什么这里我要这样做吗\N{\fs12}Okay? So do you see why I had to do that in this case?
Dialogue: 0,0:17:05.73,0:17:07.23,yin,,0,0,0,,因为这个completionHandler\N{\fs12}Because this completionHandler
Dialogue: 0,0:17:07.34,0:17:08.69,yin,,0,0,0,,不是在主队列上被调用的\N{\fs12}is not being called on the main queue,
Dialogue: 0,0:17:08.70,0:17:10.06,yin,,0,0,0,,是在另外一个队列上\N{\fs12}it's being called on a different queue.
Dialogue: 0,0:17:10.40,0:17:12.78,yin,,0,0,0,,这就是iOS中要理解的一点\N{\fs12}So this is what, what you need to understand in iOS is,
Dialogue: 0,0:17:13.03,0:17:16.62,yin,,0,0,0,,将block传递给某个方法时\N{\fs12}when I have a block that's passed to some method,
Dialogue: 0,0:17:16.88,0:17:18.70,yin,,0,0,0,,要知道它会在哪个队列上被调用\N{\fs12}what queue is it going to be called on.
Dialogue: 0,0:17:18.90,0:17:21.44,yin,,0,0,0,,大多数情况下 向iOS方法传递block时\N{\fs12}Now most time when you pass a block to an iOS method,
Dialogue: 0,0:17:21.50,0:17:23.50,yin,,0,0,0,,会在调用该方法的那个队列上\N{\fs12}it's going to call it on the same queue
Dialogue: 0,0:17:23.65,0:17:24.96,yin,,0,0,0,,调用这个block\N{\fs12}that you called that method on.
Dialogue: 0,0:17:25.15,0:17:27.19,yin,,0,0,0,,调用任意方法 给它一个block\N{\fs12}Whatever method you called and you handed it a block,
Dialogue: 0,0:17:27.44,0:17:29.34,yin,,0,0,0,,大多数情况下 会在同一个队列上进行回调\N{\fs12}it'll call you back on the same queue, most of the time.
Dialogue: 0,0:17:29.82,0:17:32.60,yin,,0,0,0,,但如果是像这里的这个方法一样\N{\fs12}But if the method, like this one,
Dialogue: 0,0:17:32.61,0:17:34.74,yin,,0,0,0,,在执行过程中 在其他队列上做了操作\N{\fs12}goes off and does something in another queue,
Dialogue: 0,0:17:34.84,0:17:37.02,yin,,0,0,0,,就可能会在另一个队列上进行回调\N{\fs12}then it's probably gonna call you back in some other queue,
Dialogue: 0,0:17:37.03,0:17:39.54,yin,,0,0,0,,除非你为其指定了主队列\N{\fs12}unless you specify the main queue, okay?
Dialogue: 0,0:17:40.07,0:17:40.51,yin,,0,0,0,,有问题吗\N{\fs12}Question?
Dialogue: 0,0:17:41.35,0:17:43.93,yin,,0,0,0,,[学生提问]\N{\fs12}[Student: inaudible]
Dialogue: 0,0:17:44.39,0:17:46.91,yin,,0,0,0,,dispatch_async调用是线程安全的吗\N{\fs12}Is the call dispatch async thread safe?
Dialogue: 0,0:17:46.91,0:17:48.30,yin,,0,0,0,,是的\N{\fs12}And the answer is yes it is.
Dialogue: 0,0:17:48.38,0:17:50.85,yin,,0,0,0,,实际上 你可以将其用于线程同步\N{\fs12}And so you can use it for thread synchronization, actually,
Dialogue: 0,0:17:50.95,0:17:52.14,yin,,0,0,0,,因为它是线程安全的\N{\fs12}because it is thread safe.
Dialogue: 0,0:17:52.14,0:17:54.89,yin,,0,0,0,,它是原子调用 是原子的\N{\fs12}It's an atomic call, okay, it happens atomically.
Dialogue: 0,0:17:54.90,0:17:55.93,yin,,0,0,0,,其他操作出现时\N{\fs12}It can't be interrupted
Dialogue: 0,0:17:56.27,0:17:58.00,yin,,0,0,0,,它不会被中断\N{\fs12}by something else coming in and doing it.
Dialogue: 0,0:17:58.16,0:17:59.43,yin,,0,0,0,,这是个好问题\N{\fs12}So, that's a good question.
Dialogue: 0,0:18:00.51,0:18:03.62,yin,,0,0,0,,大家注意到这个task resume了吗\N{\fs12}Notice all, the small thing, you notice I have task resume,
Dialogue: 0,0:18:03.62,0:18:04.68,yin,,0,0,0,,看到这个恢复任务了吗\N{\fs12}you see that task resume?
Dialogue: 0,0:18:04.90,0:18:07.30,yin,,0,0,0,,如果用它创建了一个下载任务\N{\fs12}When you create a download task using this,
Dialogue: 0,0:18:07.47,0:18:10.78,yin,,0,0,0,,开始时会被挂起 也就是暂停下载\N{\fs12}it starts out suspended, in other words, not downloaded.
Dialogue: 0,0:18:11.23,0:18:14.20,yin,,0,0,0,,所以你需要立刻重新开始下载\N{\fs12}So you have to immediately resume it to start it, okay?
Dialogue: 0,0:18:14.20,0:18:16.04,yin,,0,0,0,,重新开始操作\N{\fs12}Now that resume is going to start something
Dialogue: 0,0:18:16.06,0:18:18.18,yin,,0,0,0,,会在另一个线程执行 而非主队列\N{\fs12}happening in a different thread, not on a main thread,
Dialogue: 0,0:18:18.46,0:18:20.11,yin,,0,0,0,,但也要恢复任务\N{\fs12}but still, task resume,
Dialogue: 0,0:18:20.12,0:18:22.55,yin,,0,0,0,,不要忘了task resume\N{\fs12}don't forget the task resume, okay?
Dialogue: 0,0:18:23.40,0:18:24.66,yin,,0,0,0,,这就是多线程的内容\N{\fs12}Okay, that's it for multithreading.
Dialogue: 0,0:18:24.69,0:18:25.93,yin,,0,0,0,,我会在示例中演示\N{\fs12}I'm going to do it in the demo,
Dialogue: 0,0:18:26.09,0:18:27.44,yin,,0,0,0,,大家还会再看一遍\N{\fs12}so you'll get another look at it.
Dialogue: 0,0:18:27.81,0:18:29.06,yin,,0,0,0,,大家要在作业中实现这部分\N{\fs12}You'll be doing it in your homework
Dialogue: 0,0:18:29.06,0:18:30.15,yin,,0,0,0,,所以你们会熟悉它的\N{\fs12}so you'll get a feel for it.
Dialogue: 0,0:18:30.42,0:18:32.02,yin,,0,0,0,,主要就是要理解这个思路\N{\fs12}The idea here is to get this idea,
Dialogue: 0,0:18:32.03,0:18:33.43,yin,,0,0,0,,主队列和其他队列\N{\fs12}this main queue and these other queues,
Dialogue: 0,0:18:33.44,0:18:35.73,yin,,0,0,0,,在其他队列中做任何操作时\N{\fs12}and that I have to post back to the main queue
Dialogue: 0,0:18:35.74,0:18:37.52,yin,,0,0,0,,都要向主队列回传消息\N{\fs12}anytime I'm doing something on another queue.
Dialogue: 0,0:18:38.79,0:18:40.37,yin,,0,0,0,,然后是UIScrollView滚动视图\N{\fs12}Okay. UIScrollView.
Dialogue: 0,0:18:40.37,0:18:42.56,yin,,0,0,0,,UIScrollView是一个很重要的视图\N{\fs12}So UIScrollView is a really important view.
Dialogue: 0,0:18:42.98,0:18:45.02,yin,,0,0,0,,iPhone屏幕很小\N{\fs12}You know, the iPhone screen,
Dialogue: 0,0:18:45.04,0:18:46.89,yin,,0,0,0,,任何能装进口袋的设备\N{\fs12}anything that's going to fit in your pocket
Dialogue: 0,0:18:46.90,0:18:48.02,yin,,0,0,0,,屏幕都很小\N{\fs12}is going to have a small screen,
Dialogue: 0,0:18:48.23,0:18:49.27,yin,,0,0,0,,但你可能想用它\N{\fs12}but you might want to have it
Dialogue: 0,0:18:49.28,0:18:51.69,yin,,0,0,0,,看很多信息\N{\fs12}looking at a lot of information, okay?
Dialogue: 0,0:18:51.88,0:18:53.32,yin,,0,0,0,,希望能够轻松导航至所需位置\N{\fs12}And you want to easily navigate through that.
Dialogue: 0,0:18:53.32,0:18:54.73,yin,,0,0,0,,这里有一小段视频\N{\fs12}Now I have this little video here,
Dialogue: 0,0:18:54.74,0:18:56.77,yin,,0,0,0,,好像是iOS4的\N{\fs12}this is like from iOS 4, or something,
Dialogue: 0,0:18:56.78,0:18:57.80,yin,,0,0,0,,所以这里...\N{\fs12}that's why I left it with the...
Dialogue: 0,0:18:58.16,0:19:00.89,yin,,0,0,0,,所以用的是旧款iPhone的背景\N{\fs12}or it has the old background, the old kind of phone,
Dialogue: 0,0:19:01.15,0:19:03.45,yin,,0,0,0,,但它能很好地展示滚动视图的作用\N{\fs12}but it's really good at showing what scroll view can do,
Dialogue: 0,0:19:03.45,0:19:06.95,yin,,0,0,0,,滚动视图中可以添加任意视图\N{\fs12}because you can put any kind of view in a scroll view,
Dialogue: 0,0:19:06.95,0:19:08.47,yin,,0,0,0,,包括另一个滚动视图\N{\fs12}including another scroll view.
Dialogue: 0,0:19:09.17,0:19:10.65,yin,,0,0,0,,可以看到这里的滚动视图\N{\fs12}So you can see that I've got a scroll view
Dialogue: 0,0:19:10.66,0:19:11.94,yin,,0,0,0,,是水平滚动的\N{\fs12}that's scrolling horizontally,
Dialogue: 0,0:19:11.96,0:19:14.05,yin,,0,0,0,,而其中内容是垂直滚动的\N{\fs12}and the things in it are scrolling vertically.
Dialogue: 0,0:19:14.48,0:19:15.97,yin,,0,0,0,,这是一个股票应用\N{\fs12}Okay? Or here's a stock app
Dialogue: 0,0:19:16.14,0:19:17.63,yin,,0,0,0,,多个滚动视图\N{\fs12}where I'm going scrolling horizontally
Dialogue: 0,0:19:17.88,0:19:19.69,yin,,0,0,0,,可以水平滚动\N{\fs12}through other scroll views
Dialogue: 0,0:19:19.76,0:19:21.69,yin,,0,0,0,,而每个视图内部可以垂直滚动\N{\fs12}that can scroll vertically inside of them.
Dialogue: 0,0:19:22.17,0:19:22.71,yin,,0,0,0,,看到了吗\N{\fs12}You see that?
Dialogue: 0,0:19:23.00,0:19:24.91,yin,,0,0,0,,所以这里可以显示出很多信息\N{\fs12}So I can present a lot of information here,
Dialogue: 0,0:19:24.91,0:19:26.42,yin,,0,0,0,,不只有股票报价\N{\fs12}not just t
Download .txt
gitextract_oegomsf2/

├── .gitignore
├── Hiragino Sans GB W3.otf
├── README.md
└── Subtitles/
    ├── 1. Class Logistics, Overview of iOS, MVC, Objective-C.ass
    ├── 10. Multithreading, Scroll View.ass
    ├── 11. Table View and iPad.ass
    ├── 12. Documents and Core Data.ass
    ├── 13. Core Data and Table View.ass
    ├── 14. UIApplication, Network Activity Indicator, and Maps.ass
    ├── 15. MapKit and Embed Segue.ass
    ├── 16. Modal Segues, Text Fields, Alerts, and Action Sheets.ass
    ├── 17. Camera, Core Motion, Application Lifecycle.ass
    ├── 18. Localization, Adding UI to Settings.ass
    ├── 2. Xcode 5.ass
    ├── 3. Objective-C.ass
    ├── 4. Foundation and Attributed Strings.ass
    ├── 5. View Controller Lifecycle.ass
    ├── 6. Polymorphism with Controllers, UINavigation, UITabBar.ass
    ├── 7. Views and Gestures.ass
    ├── 8. Protocols, Blocks, and Animation.ass
    └── 9. Animation and Autolayout.ass
Condensed preview — 21 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (4,038K chars).
[
  {
    "path": ".gitignore",
    "chars": 9,
    "preview": ".DS_Store"
  },
  {
    "path": "README.md",
    "chars": 707,
    "preview": "斯坦福大学公开课:iOS 7 应用开发\n===============================\n\n# 剧终\n\nDemo\n----\n\n![](http://ww4.sinaimg.cn/large/69fe98c3gw1eelg25q"
  },
  {
    "path": "Subtitles/1. Class Logistics, Overview of iOS, MVC, Objective-C.ass",
    "chars": 143145,
    "preview": "[Script Info]\r\n; Script generated by Aegisub 3.1.2\r\n; http://www.aegisub.org/\r\nTitle: Default Aegisub file\r\nScriptType:"
  },
  {
    "path": "Subtitles/10. Multithreading, Scroll View.ass",
    "chars": 198294,
    "preview": "[Script Info]\r\n; Script generated by Aegisub 3.2.0\r\n; http://www.aegisub.org/\r\nTitle: Default Aegisub file\r\nScriptType:"
  },
  {
    "path": "Subtitles/11. Table View and iPad.ass",
    "chars": 223434,
    "preview": "[Script Info]\r\n; Script generated by Aegisub 3.2.0\r\n; http://www.aegisub.org/\r\nTitle: Default Aegisub file\r\nScriptType:"
  },
  {
    "path": "Subtitles/12. Documents and Core Data.ass",
    "chars": 190240,
    "preview": "[Script Info]\r\n; Script generated by Aegisub 3.2.0\r\n; http://www.aegisub.org/\r\nTitle: Default Aegisub file\r\nScriptType:"
  },
  {
    "path": "Subtitles/13. Core Data and Table View.ass",
    "chars": 175044,
    "preview": "[Script Info]\r\n; Script generated by Aegisub 3.2.0\r\n; http://www.aegisub.org/\r\nTitle: Default Aegisub file\r\nScriptType:"
  },
  {
    "path": "Subtitles/14. UIApplication, Network Activity Indicator, and Maps.ass",
    "chars": 179142,
    "preview": "[Script Info]\r\n; Script generated by Aegisub 3.2.0\r\n; http://www.aegisub.org/\r\nTitle: Default Aegisub file\r\nScriptType:"
  },
  {
    "path": "Subtitles/15. MapKit and Embed Segue.ass",
    "chars": 194753,
    "preview": "[Script Info] \r\n; Script generated by Aegisub 3.2.0 \r\n; http://www.aegisub.org/ \r\nTitle: Default Aegisub file \r\nScriptT"
  },
  {
    "path": "Subtitles/16. Modal Segues, Text Fields, Alerts, and Action Sheets.ass",
    "chars": 191676,
    "preview": "[Script Info]\r\n; Script generated by Aegisub 3.2.0\r\n; http://www.aegisub.org/\r\nTitle: Default Aegisub file\r\nScriptType:"
  },
  {
    "path": "Subtitles/17. Camera, Core Motion, Application Lifecycle.ass",
    "chars": 169873,
    "preview": "[Script Info]\r\n; Script generated by Aegisub 3.2.0\r\n; http://www.aegisub.org/\r\nTitle: Default Aegisub file\r\nScriptType:"
  },
  {
    "path": "Subtitles/18. Localization, Adding UI to Settings.ass",
    "chars": 160917,
    "preview": "[Script Info]\r\n; Script generated by Aegisub 3.2.0\r\n; http://www.aegisub.org/\r\nTitle: Default Aegisub file\r\nScriptType:"
  },
  {
    "path": "Subtitles/2. Xcode 5.ass",
    "chars": 188167,
    "preview": "[Script Info]\r\n; Script generated by Aegisub 3.1.2\r\n; http://www.aegisub.org/\r\nTitle: Default Aegisub file\r\nScriptType:"
  },
  {
    "path": "Subtitles/3. Objective-C.ass",
    "chars": 159817,
    "preview": "[Script Info]\r\n; Script generated by Aegisub 3.1.2\r\n; http://www.aegisub.org/\r\nTitle: Default Aegisub file\r\nScriptType:"
  },
  {
    "path": "Subtitles/4. Foundation and Attributed Strings.ass",
    "chars": 178709,
    "preview": "[Script Info]\r\n; Script generated by Aegisub 3.1.2\r\n; http://www.aegisub.org/\r\nTitle: Default Aegisub file\r\nScriptType:"
  },
  {
    "path": "Subtitles/5. View Controller Lifecycle.ass",
    "chars": 186493,
    "preview": "[Script Info]\r\n; Script generated by Aegisub 3.1.2\r\n; http://www.aegisub.org/\r\nTitle: Default Aegisub file\r\nScriptType:"
  },
  {
    "path": "Subtitles/6. Polymorphism with Controllers, UINavigation, UITabBar.ass",
    "chars": 201339,
    "preview": "[Script Info]\r\n; Script generated by Aegisub 3.1.2\r\n; http://www.aegisub.org/\r\nTitle: Default Aegisub file\r\nScriptType:"
  },
  {
    "path": "Subtitles/7. Views and Gestures.ass",
    "chars": 216002,
    "preview": "[Script Info]\r\n; Script generated by Aegisub 3.1.3\r\n; http://www.aegisub.org/\r\nTitle: Default Aegisub file\r\nScriptType:"
  },
  {
    "path": "Subtitles/8. Protocols, Blocks, and Animation.ass",
    "chars": 199615,
    "preview": "[Script Info]\r\n; Script generated by Aegisub 3.1.3\r\n; http://www.aegisub.org/\r\nTitle: Default Aegisub file\r\nScriptType:"
  },
  {
    "path": "Subtitles/9. Animation and Autolayout.ass",
    "chars": 183745,
    "preview": "[Script Info]\r\n; Script generated by Aegisub 3.2.0\r\n; http://www.aegisub.org/\r\nTitle: Default Aegisub file\r\nScriptType:"
  }
]

// ... and 1 more files (download for full content)

About this extraction

This page contains the full source code of the jkyin/Subtitle GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 21 files (15.8 MB), approximately 836.4k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!