Skip to content

Commit 54a87df

Browse files
committed
443~497
1 parent 9b0ea59 commit 54a87df

File tree

1 file changed

+60
-5
lines changed

1 file changed

+60
-5
lines changed

subtitles/3. More Swift and the Foundation Framework.srt

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -875,12 +875,12 @@ Optional 的世界中取出来只是为了强调它们
875875
176
876876
00:09:25,532 --> 00:09:27,432
877877
because there's a lot in the reading that you're doing
878-
// todo
878+
因为这有很多你已经阅读过的关于 Optional 的东西了
879879

880880
177
881881
00:09:27,501 --> 00:09:29,934
882882
about optional, but these are kind of the highlights.
883-
// todo
883+
但是还是有一些强调点的
884884

885885
178
886886
00:09:30,003 --> 00:09:32,437
@@ -2011,7 +2011,7 @@ But they're new to a lot of you, and so I'm gonna try and
20112011
403
20122012
00:21:58,886 --> 00:22:01,119
20132013
ease you in with these ones that are more familiar,
2014-
// todo
2014+
等你们更熟悉时你们就会更方便地理解它
20152015

20162016
404
20172017
00:22:01,188 --> 00:22:03,855
@@ -2202,7 +2202,7 @@ it means you can't call any of its mutable functions, So
22022202
441
22032203
00:23:52,199 --> 00:23:55,800
22042204
you can't do perform operation on it. Now in assignment two,
2205-
你不能对它进行操作。现在在任务二中
2205+
你不能对它进行操作。在任务二中
22062206

22072207
442
22082208
00:23:55,869 --> 00:23:58,704
@@ -2212,222 +2212,277 @@ I'm gonna have you add a method to the calculator brain
22122212
443
22132213
00:23:58,772 --> 00:24:01,539
22142214
that is gonna let you use the calculator brain when it's
2215+
那使你们在当 CalculatorBrain 是不可改变的时候
22152216

22162217
444
22172218
00:24:01,608 --> 00:24:04,843
22182219
immutable, which is kinda cool. You still wouldn't be
2220+
使用它,这很酷。你依然不能
22192221

22202222
445
22212223
00:24:04,912 --> 00:24:07,545
22222224
able to perform operation but you can be able to something
2225+
操作它但是你可以做一些重要的
22232226

22242227
446
22252228
00:24:07,614 --> 00:24:12,350
22262229
very important, immutably. Now because of this, this kind of
2230+
不可改变的事情。因此,值类型的
22272231

22282232
447
22292233
00:24:12,419 --> 00:24:15,487
2230-
copyright-on-write behavior of value types, you must,
2234+
copy-on-write behavior of value types, you must,
2235+
写入时复制的行为,你必须
22312236

22322237
448
22332238
00:24:15,556 --> 00:24:18,957
22342239
of course, mark all the functions that are going to
2240+
标记所有函数
22352241

22362242
449
22372243
00:24:19,026 --> 00:24:23,094
22382244
modify it as mutating. And that's how the Swift knows,
2245+
并且这也是 Swift 知道
22392246

22402247
450
22412248
00:24:23,163 --> 00:24:27,299
22422249
"Oops, I've gotta make a copy of this, an actual real copy,
2250+
“哦,我得到了它的一个拷贝,一个真正的拷贝
22432251

22442252
451
22452253
00:24:27,368 --> 00:24:31,135
22462254
if someone writes to it". Now a reference class is pretty
2255+
如果有人往它里面写数据的话。“引用类型是很
22472256

22482257
452
22492258
00:24:31,204 --> 00:24:34,639
22502259
different in that it gets stored in the heap somewhere
2260+
不同的,它被储存在一个堆中
22512261

22522262
453
22532263
00:24:34,708 --> 00:24:37,909
22542264
with a pointer to it, and when you pass it around to
2265+
有一个指针指向它,当你把它传送到
22552266

22562267
454
22572268
00:24:37,978 --> 00:24:41,713
22582269
a function or to assign it to another variable or something
2270+
函数中或将它分配给另一个变量之类的东西时
22592271

22602272
455
22612273
00:24:41,782 --> 00:24:46,618
22622274
like that, you're just passing a pointer around to it.
2275+
你只是在传送指向它的指针
22632276

22642277
456
22652278
00:24:46,687 --> 00:24:51,089
22662279
Now, by the way, when you say, let x equal a reference type,
2280+
现在,顺带一提,当你写,let x = 一个引用类型时
22672281

22682282
457
22692283
00:24:51,158 --> 00:24:54,626
22702284
you can still send it messages that will mutate it.
2285+
你依然可以给它发送使它转变的信息
22712286

22722287
458
22732288
00:24:55,996 --> 00:24:58,764
22742289
All you're saying is the pointer can't change, but
2290+
你们都被告知指针是不能改变的,但是
22752291

22762292
459
22772293
00:24:58,833 --> 00:25:01,533
22782294
what it points to can always be changed.
2295+
指针指向的东西在任何时候都能改变
22792296

22802297
460
22812298
00:25:01,601 --> 00:25:05,137
22822299
Now reference types are what you're used to.
2300+
引用类型是你们习惯的
22832301

22842302
461
22852303
00:25:05,205 --> 00:25:08,974
22862304
Most languages that have object-oriented reference
2305+
大部分语言都有面向对象的引用
22872306

22882307
462
22892308
00:25:09,043 --> 00:25:15,213
22902309
types. Reference types are a little bit Wild West- I
2310+
类型。引用类型有点狂野——我
22912311

22922312
463
22932313
00:25:15,282 --> 00:25:17,816
22942314
don't have time to teach you this, I hope you'll get to see
2315+
没时间给你们讲这个,我希望你们在斯坦福的时光里可以
22952316

22962317
464
22972318
00:25:17,885 --> 00:25:19,651
22982319
this sometime in your career at Stanford, but
2320+
可以见到它
22992321

23002322
465
23012323
00:25:19,720 --> 00:25:21,820
23022324
there is a different way of thinking about programming
2325+
有一种不同的编程思想,它与你们之前
23032326

23042327
466
23052328
00:25:21,888 --> 00:25:23,988
23062329
than you're used to: it's called functional programming.
2330+
接触到的不同:它叫做函数式编程
23072331

23082332
467
23092333
00:25:24,057 --> 00:25:25,089
23102334
How many people have heard the phrase,
2335+
有多少人曾经听说过这个词
23112336

23122337
468
23132338
00:25:25,158 --> 00:25:29,227
23142339
functional programming? So about half of you. The idea
2340+
函数式编程?有一半左右。函数式编程
23152341

23162342
469
23172343
00:25:29,296 --> 00:25:31,663
23182344
of functional programming is: you don't want this Wild West
2345+
的思想是:你不想要这样的狂野
23192346

23202347
470
23212348
00:25:31,732 --> 00:25:34,599
23222349
where you've got these objects with multiple people pointing
2350+
你得到这些有多人指向它们的对象
23232351

23242352
471
23252353
00:25:34,668 --> 00:25:37,936
23262354
at them, any of whom could modify it at any time.
2355+
它们中任何一个在任何时间都能修改它
23272356

23282357
472
23292358
00:25:38,004 --> 00:25:41,105
23302359
That leaves you open to a lot of difficulty in verifying
2360+
这给你核实你的程序的正确性
23312361

23322362
473
23332363
00:25:41,174 --> 00:25:42,975
23342364
the correctness of your program.
2365+
带来了不小的困难
23352366

23362367
474
23372368
00:25:43,043 --> 00:25:46,278
23382369
Whereas if you have a lot of objects that are immutable,
2370+
然而如果你有一大堆不可改变的对象
23392371

23402372
475
23412373
00:25:46,346 --> 00:25:49,715
23422374
you know they can't change, and their APIs are basically
2375+
你知道它们不可能被改变,并且它们的 API 基本上
23432376

23442377
476
23452378
00:25:49,783 --> 00:25:52,718
23462379
like mathematical functions where data goes in and
2380+
类似于数学函数,数据输入后
23472381

23482382
477
23492383
00:25:52,786 --> 00:25:55,520
23502384
predictable data comes out, because there's
2385+
可预计的数据输出,因为
23512386

23522387
478
23532388
00:25:55,588 --> 00:25:59,291
23542389
not all this side-effecting, data-effecting other objects
2390+
不是所有 // todo
23552391

23562392
479
23572393
00:25:59,359 --> 00:26:02,194
23582394
that someone else is pointing to in all this.
2395+
// todo
23592396

23602397
480
23612398
00:26:02,262 --> 00:26:04,595
23622399
It's this really well-contained little thing.
2400+
这是个非常好的东西
23632401

23642402
481
23652403
00:26:04,664 --> 00:26:08,433
23662404
Now iOS was not developed with functional programming in mind
2405+
iOS 完全不是由函数式编程
23672406

23682407
482
23692408
00:26:08,502 --> 00:26:11,603
23702409
at all. But the people who invented Swift,
2410+
开发的。但是发明 Swift 的这群人
23712411

23722412
483
23732413
00:26:11,671 --> 00:26:15,074
23742414
they were thinking about functional programming, So
2415+
它们用函数式编程思考,所以
23752416

23762417
484
23772418
00:26:15,142 --> 00:26:17,009
23782419
you can kind of mix a lot of the elements of
2420+
你可以混合很多函数式编程
23792421

23802422
485
23812423
00:26:17,077 --> 00:26:19,244
23822424
functional programming into your application,
2425+
的元素到你的应用程序中
23832426

23842427
486
23852428
00:26:19,312 --> 00:26:22,080
23862429
if you're building an iOS application. Now that's a new
2430+
如果你正在开发一款 iOS 应用程序。现在它是 iOS 的
23872431

23882432
487
23892433
00:26:22,149 --> 00:26:26,051
23902434
frontier in iOS, because for however long, 20 years,
2435+
新边界,因为不管多久,20年
23912436

23922437
488
23932438
00:26:26,119 --> 00:26:28,120
23942439
really, or 30 years, really, if you consider all the way
2440+
或是30年,如果你考虑到
23952441

23962442
489
23972443
00:26:28,188 --> 00:26:31,723
23982444
back to the invention of the technology that led to iOS,
2445+
所有的引领 iOS 的技术的发明
23992446

24002447
490
24012448
00:26:31,792 --> 00:26:36,028
24022449
people have been programming with basically
2450+
人们已经基本上只在
24032451

24042452
491
24052453
00:26:36,096 --> 00:26:39,831
24062454
reference types only, for their object-orienting.
2455+
面向对象时用引用类型编程
24072456

24082457
492
24092458
00:26:39,900 --> 00:26:42,534
24102459
But when you do this programming with structs and
2460+
但当你用结构体和枚举,特别是协议
24112461

24122462
493
24132463
00:26:42,603 --> 00:26:46,104
24142464
enums, and especially when you throw in protocols, (which I
2465+
(就是我给你说的那个可重要的,但是
24152466
24162467
494
24172468
00:26:46,173 --> 00:26:47,939
24182469
told you I was gonna tell you that are very important, but
2470+
现在不能给你讲的那个东西,以及泛型)
24192471

24202472
495
24212473
00:26:48,008 --> 00:26:51,843
24222474
I cannot explain to you yet, and generics),
2475+
编程时,当你开始完全掌握
24232476

24242477
496
24252478
00:26:51,912 --> 00:26:54,579
24262479
when you start throwing those things all in there, you can
2480+
这些所有的东西时,你就
24272481

24282482
497
24292483
00:26:54,648 --> 00:26:58,216
24302484
really do a good job of doing real functional programming.
2485+
真的可以把函数式编程做的很好了
24312486

24322487
498
24332488
00:26:58,285 --> 00:27:02,153

0 commit comments

Comments
 (0)