Skip to content

Commit b81dd16

Browse files
committed
3_801-855
1 parent 4c11aff commit b81dd16

File tree

1 file changed

+58
-3
lines changed

1 file changed

+58
-3
lines changed

subtitles/3. Swift Programming Language.srt

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3205,222 +3205,277 @@ it means that setting this var is private, but getting it
32053205
801
32063206
00:40:39,270 --> 00:40:43,639
32073207
is not private. So you allow people to get the var, access
3208+
并不是私有的。所以你允许人们得到这个变量,访问
32083209

32093210
802
32103211
00:40:43,708 --> 00:40:46,676
3211-
it, but they can not set it. That's you point of view,
3212+
it, but they can not set it. That's you purview,
3213+
这个变量,但是不能给它赋值。那是你的权利
32123214

32133215
803
32143216
00:40:46,744 --> 00:40:48,611
32153217
that's your internal implementation sets it.
3218+
你的内部实现可以给它赋值
32163219

32173220
804
32183221
00:40:48,679 --> 00:40:51,514
32193222
We'll see a good example of that in concentration.
3223+
我们会在翻牌游戏里看到个好的例子
32203224

32213225
805
32223226
00:40:51,583 --> 00:40:54,850
32233227
And then there's fileprivate. Fileprivate in a Swift file,
3228+
然后是 fileprivate,文件内私有。在一个 Swift 文件里
32243229

32253230
806
32263231
00:40:54,919 --> 00:40:56,852
32273232
you can have multiple classes and structs in there,
3233+
你可以有多个类和结构体
32283234

32293235
807
32303236
00:40:56,921 --> 00:40:58,955
32313237
you don't have to be just one class which is what we've done
3238+
不需要想我们现在这样一个文件只有一个类
32323239

32333240
808
32343241
00:40:59,024 --> 00:41:02,158
32353242
so far and fileprivate means anything in that in that
3243+
而 fileprivate 的意思是,任何在那个
32363244

32373245
809
32383246
00:41:02,227 --> 00:41:06,162
32393247
file can access each other, right. So classes,
3248+
文件里的都可以互相访问,也就是类
32403249

32413250
810
32423251
00:41:06,230 --> 00:41:09,665
3243-
four classes in there, it can each others methods, okay,
3252+
all classes in there, it can each others methods, okay,
3253+
所有的都可以访问 fileprivate 的方法(和变量)
32443254

32453255
811
32463256
00:41:09,734 --> 00:41:12,501
32473257
that's what file private means. Okay, the other ones
3258+
这就是 fileprivate 的意思。好,其他的
32483259

32493260
812
32503261
00:41:12,570 --> 00:41:15,204
32513262
are public and open, those are for framework writers.
3263+
public 和 open,这两个是给框架作者用的
32523264

32533265
813
32543266
00:41:15,273 --> 00:41:18,007
32553267
Public means that people outside the framework
3268+
public 的意思是编写框架以外的人
32563269

32573270
814
32583271
00:41:18,076 --> 00:41:21,444
32593272
can call it. Doesn't make sense for outside your app,
3273+
也可以调用它。在你的程序外使用是说不通的
32603274

32613275
815
32623276
00:41:21,512 --> 00:41:23,746
32633277
that would never happen, so outside your framework.
3278+
这也不可能发生,所以是在框架外使用
32643279

32653280
816
32663281
00:41:23,815 --> 00:41:26,416
32673282
And open means not only can people outside your framework
3283+
open 的意思是不仅框架外可以
32683284

32693285
817
32703286
00:41:26,484 --> 00:41:29,585
32713287
call it but they could sub class that class,
3288+
调用,他们还可以继承那个类
32723289

32733290
818
32743291
00:41:29,654 --> 00:41:31,320
32753292
override your methods all that stuff,
3293+
重写你的方法等
32763294

32773295
819
32783296
00:41:31,388 --> 00:41:35,124
32793297
so open is like wide open, okay. We don't care about that
3298+
所以 open 是很开放的权限。但我们不用管
32803299

32813300
820
32823301
00:41:35,193 --> 00:41:38,361
32833302
cuz we're only, we're not doing frameworks, right. So
3303+
因为我们只写程序,不会写框架,好吧,所以
32843304

32853305
821
32863306
00:41:38,430 --> 00:41:41,030
32873307
we're gonna focus on private of the various privates.
3308+
我们主要关注这几种 private
32883309

32893310
822
32903311
00:41:41,099 --> 00:41:43,999
32913312
A good strategy to use these is pretty much put private on
3313+
最好的做法是基本都用 private
32923314

32933315
823
32943316
00:41:44,068 --> 00:41:46,969
32953317
anything until you're sure, yeah I want someone else to be
3318+
除非你确信说我想要其他人
32963319

32973320
824
32983321
00:41:47,038 --> 00:41:48,904
32993322
able to call this method somewhere.
3323+
在其他地方能够调用这个方法
33003324

33013325
825
33023326
00:41:48,973 --> 00:41:53,509
33033327
Right that's by default you should make things private. So
3328+
所以默认你应该让所有的都是 private
33043329

33053330
826
33063331
00:41:53,578 --> 00:41:56,312
33073332
let's look a concentration, what it would look like to
3333+
所以让我们看看翻牌游戏,它看起来是什么样的
33083334

33093335
827
33103336
00:41:56,381 --> 00:41:58,114
3311-
put access control and concentration and
3337+
put access control on concentration and
3338+
如果我们给玩牌游戏加上访问权限的话
33123339

33133340
828
33143341
00:41:58,182 --> 00:42:00,883
33153342
pay attention here because I'm gonna require in all your
3343+
你要注意了,因为我要求你所有的
33163344

33173345
829
33183346
00:42:00,952 --> 00:42:04,153
33193347
homeworks going forward that you mark things properly.
3348+
之后的作业里正确地标记访问权限
33203349

33213350
830
33223351
00:42:04,222 --> 00:42:05,922
33233352
I want you to mark things private if they should be
3353+
我想要你把私有的都标记为 private
33243354

33253355
831
33263356
00:42:05,990 --> 00:42:08,224
33273357
private. Okay, cuz I wanna just make sure that you
3358+
因为我想要确保你
33283359

33293360
832
33303361
00:42:08,292 --> 00:42:11,895
33313362
understand what this is all about. So let's go back here
3363+
理解了这是什么。那我们回到这里
33323364

33333365
833
33343366
00:42:13,565 --> 00:42:16,665
33353367
to Xcode. Let's start with our ViewController.
3368+
到 Xcode 里,从 ViewController 开始
33363369

33373370
834
33383371
00:42:16,734 --> 00:42:19,134
33393372
Okay, we have three classes, or three data structures,
3373+
好,我们有三个类,准确说是三个数据结构
33403374

33413375
835
33423376
00:42:19,203 --> 00:42:21,304
33433377
our ViewController, Card, and Concentration. So let's start
3378+
我们的 ViewController,Card 和 Concentration。那我们从
33443379

33453380
836
33463381
00:42:21,372 --> 00:42:27,210
33473382
with ViewController. So this right here is our model. So
3383+
ViewController 开始改。所以这里的这个是我们的模型
33483384

33493385
837
33503386
00:42:27,278 --> 00:42:31,514
33513387
would we want our model to be public, to be not private?
3388+
我们想要模型是公开的,非私有的吗?
33523389

33533390
838
33543391
00:42:31,583 --> 00:42:33,582
33553392
Well that depends, actually.
3393+
其实那个不一定
33563394

33573395
839
33583396
00:42:33,651 --> 00:42:36,319
33593397
It depends of what your model is and how it works. Often,
3398+
那取决于你的模型是什么,怎么工作的。一般来说
33603399

33613400
840
33623401
00:42:36,387 --> 00:42:40,256
33633402
ViewControllers models are public by public I mean
3403+
ViewController 是公开的。我这个公开不是 public
33643404

33653405
841
33663406
00:42:40,325 --> 00:42:43,492
33673407
non-private. We're inside an app so forget about public and
3408+
意思是非私有。我们写的是一个 App,所以你可以忽略 public 和
33683409

33693410
842
33703411
00:42:43,561 --> 00:42:47,096
33713412
open keywords. I mean, when I say public I mean non-private.
3413+
open 这两个关键字。所以我所谓的 public/公开是指非私有
33723414

33733415
843
33743416
00:42:47,165 --> 00:42:49,932
33753417
So a lot of times you do because you give a model to
3418+
而大部分时候都是这样的,因为你把一个模型提供给
33763419

33773420
844
33783421
00:42:50,001 --> 00:42:51,433
33793422
a view controller and it displays it,
3423+
视图控制器,然后控制器就显示它
33803424

33813425
845
33823426
00:42:51,502 --> 00:42:54,870
33833427
that's what it does. But that is not the case here. This one
3428+
这就是他的工作。但我们这里不是这样的情况。这里
33843429

33853430
846
33863431
00:42:54,939 --> 00:42:58,240
33873432
wants to be private. And the reason it wants to be private
3433+
我们想要是 private 的。它应该是私有的
33883434

33893435
847
33903436
00:42:58,309 --> 00:43:01,477
33913437
is because the number of pairs of cards in the game is
3438+
原因是 numberOfPairsOfCards
33923439

33933440
848
33943441
00:43:01,545 --> 00:43:04,480
33953442
intimately tied to the UI, okay the number of
3443+
游戏里卡片的对数是和 UI 捆绑着的
33963444

33973445
849
33983446
00:43:04,549 --> 00:43:07,083
33993447
cards we have in the UI. So if we wanted to make
3448+
是我们 UI 理由的卡的对数。如果我们想要
34003449

34013450
850
34023451
00:43:07,151 --> 00:43:09,585
34033452
this public then we'd also have to make something public
3453+
让它公开的的话,我们也需要让另一个公开的
34043454

34053455
851
34063456
00:43:09,653 --> 00:43:13,356
34073457
to specify the number of card buttons that we allow and
3458+
来指定我们允许的显示卡片的按钮的个数
34083459

34093460
852
34103461
00:43:13,425 --> 00:43:15,391
34113462
we don't do that currently,
3463+
但我们现在并不是这样的
34123464

34133465
853
34143466
00:43:15,460 --> 00:43:18,127
34153467
that's something that is in our little scene and
3468+
那现在是我们在 Interface Builder
34163469

34173470
854
34183471
00:43:18,195 --> 00:43:21,430
34193472
interface builder, so we don't do it. So we keep this, we
3473+
的场景里设置的,所以我们不这样做。所以我们保持这个
34203474

34213475
855
34223476
00:43:21,499 --> 00:43:25,067
34233477
keep this private. How about number of pairs of cards?
3478+
让他就是 private 的。那 numberOfPairsOfCards 呢?
34243479

34253480
856
34263481
00:43:25,136 --> 00:43:28,271

0 commit comments

Comments
 (0)