@@ -3205,222 +3205,277 @@ it means that setting this var is private, but getting it
32053205801
3206320600:40:39,270 --> 00:40:43,639
32073207is not private. So you allow people to get the var, access
3208+ 并不是私有的。所以你允许人们得到这个变量,访问
32083209
32093210802
3210321100: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
32133215803
3214321600:40:46,744 --> 00:40:48,611
32153217that's your internal implementation sets it.
3218+ 你的内部实现可以给它赋值
32163219
32173220804
3218322100:40:48,679 --> 00:40:51,514
32193222We'll see a good example of that in concentration.
3223+ 我们会在翻牌游戏里看到个好的例子
32203224
32213225805
3222322600:40:51,583 --> 00:40:54,850
32233227And then there's fileprivate. Fileprivate in a Swift file,
3228+ 然后是 fileprivate,文件内私有。在一个 Swift 文件里
32243229
32253230806
3226323100:40:54,919 --> 00:40:56,852
32273232you can have multiple classes and structs in there,
3233+ 你可以有多个类和结构体
32283234
32293235807
3230323600:40:56,921 --> 00:40:58,955
32313237you don't have to be just one class which is what we've done
3238+ 不需要想我们现在这样一个文件只有一个类
32323239
32333240808
3234324100:40:59,024 --> 00:41:02,158
32353242so far and fileprivate means anything in that in that
3243+ 而 fileprivate 的意思是,任何在那个
32363244
32373245809
3238324600:41:02,227 --> 00:41:06,162
32393247file can access each other, right. So classes,
3248+ 文件里的都可以互相访问,也就是类
32403249
32413250810
3242325100: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
32453255811
3246325600:41:09,734 --> 00:41:12,501
32473257that's what file private means. Okay, the other ones
3258+ 这就是 fileprivate 的意思。好,其他的
32483259
32493260812
3250326100:41:12,570 --> 00:41:15,204
32513262are public and open, those are for framework writers.
3263+ public 和 open,这两个是给框架作者用的
32523264
32533265813
3254326600:41:15,273 --> 00:41:18,007
32553267Public means that people outside the framework
3268+ public 的意思是编写框架以外的人
32563269
32573270814
3258327100:41:18,076 --> 00:41:21,444
32593272can call it. Doesn't make sense for outside your app,
3273+ 也可以调用它。在你的程序外使用是说不通的
32603274
32613275815
3262327600:41:21,512 --> 00:41:23,746
32633277that would never happen, so outside your framework.
3278+ 这也不可能发生,所以是在框架外使用
32643279
32653280816
3266328100:41:23,815 --> 00:41:26,416
32673282And open means not only can people outside your framework
3283+ open 的意思是不仅框架外可以
32683284
32693285817
3270328600:41:26,484 --> 00:41:29,585
32713287call it but they could sub class that class,
3288+ 调用,他们还可以继承那个类
32723289
32733290818
3274329100:41:29,654 --> 00:41:31,320
32753292override your methods all that stuff,
3293+ 重写你的方法等
32763294
32773295819
3278329600:41:31,388 --> 00:41:35,124
32793297so open is like wide open, okay. We don't care about that
3298+ 所以 open 是很开放的权限。但我们不用管
32803299
32813300820
3282330100:41:35,193 --> 00:41:38,361
32833302cuz we're only, we're not doing frameworks, right. So
3303+ 因为我们只写程序,不会写框架,好吧,所以
32843304
32853305821
3286330600:41:38,430 --> 00:41:41,030
32873307we're gonna focus on private of the various privates.
3308+ 我们主要关注这几种 private
32883309
32893310822
3290331100:41:41,099 --> 00:41:43,999
32913312A good strategy to use these is pretty much put private on
3313+ 最好的做法是基本都用 private
32923314
32933315823
3294331600:41:44,068 --> 00:41:46,969
32953317anything until you're sure, yeah I want someone else to be
3318+ 除非你确信说我想要其他人
32963319
32973320824
3298332100:41:47,038 --> 00:41:48,904
32993322able to call this method somewhere.
3323+ 在其他地方能够调用这个方法
33003324
33013325825
3302332600:41:48,973 --> 00:41:53,509
33033327Right that's by default you should make things private. So
3328+ 所以默认你应该让所有的都是 private
33043329
33053330826
3306333100:41:53,578 --> 00:41:56,312
33073332let's look a concentration, what it would look like to
3333+ 所以让我们看看翻牌游戏,它看起来是什么样的
33083334
33093335827
3310333600:41:56,381 --> 00:41:58,114
3311- put access control and concentration and
3337+ put access control on concentration and
3338+ 如果我们给玩牌游戏加上访问权限的话
33123339
33133340828
3314334100:41:58,182 --> 00:42:00,883
33153342pay attention here because I'm gonna require in all your
3343+ 你要注意了,因为我要求你所有的
33163344
33173345829
3318334600:42:00,952 --> 00:42:04,153
33193347homeworks going forward that you mark things properly.
3348+ 之后的作业里正确地标记访问权限
33203349
33213350830
3322335100:42:04,222 --> 00:42:05,922
33233352I want you to mark things private if they should be
3353+ 我想要你把私有的都标记为 private
33243354
33253355831
3326335600:42:05,990 --> 00:42:08,224
33273357private. Okay, cuz I wanna just make sure that you
3358+ 因为我想要确保你
33283359
33293360832
3330336100:42:08,292 --> 00:42:11,895
33313362understand what this is all about. So let's go back here
3363+ 理解了这是什么。那我们回到这里
33323364
33333365833
3334336600:42:13,565 --> 00:42:16,665
33353367to Xcode. Let's start with our ViewController.
3368+ 到 Xcode 里,从 ViewController 开始
33363369
33373370834
3338337100:42:16,734 --> 00:42:19,134
33393372Okay, we have three classes, or three data structures,
3373+ 好,我们有三个类,准确说是三个数据结构
33403374
33413375835
3342337600:42:19,203 --> 00:42:21,304
33433377our ViewController, Card, and Concentration. So let's start
3378+ 我们的 ViewController,Card 和 Concentration。那我们从
33443379
33453380836
3346338100:42:21,372 --> 00:42:27,210
33473382with ViewController. So this right here is our model. So
3383+ ViewController 开始改。所以这里的这个是我们的模型
33483384
33493385837
3350338600:42:27,278 --> 00:42:31,514
33513387would we want our model to be public, to be not private?
3388+ 我们想要模型是公开的,非私有的吗?
33523389
33533390838
3354339100:42:31,583 --> 00:42:33,582
33553392Well that depends, actually.
3393+ 其实那个不一定
33563394
33573395839
3358339600:42:33,651 --> 00:42:36,319
33593397It depends of what your model is and how it works. Often,
3398+ 那取决于你的模型是什么,怎么工作的。一般来说
33603399
33613400840
3362340100:42:36,387 --> 00:42:40,256
33633402ViewControllers models are public by public I mean
3403+ ViewController 是公开的。我这个公开不是 public
33643404
33653405841
3366340600:42:40,325 --> 00:42:43,492
33673407non-private. We're inside an app so forget about public and
3408+ 意思是非私有。我们写的是一个 App,所以你可以忽略 public 和
33683409
33693410842
3370341100:42:43,561 --> 00:42:47,096
33713412open keywords. I mean, when I say public I mean non-private.
3413+ open 这两个关键字。所以我所谓的 public/公开是指非私有
33723414
33733415843
3374341600:42:47,165 --> 00:42:49,932
33753417So a lot of times you do because you give a model to
3418+ 而大部分时候都是这样的,因为你把一个模型提供给
33763419
33773420844
3378342100:42:50,001 --> 00:42:51,433
33793422a view controller and it displays it,
3423+ 视图控制器,然后控制器就显示它
33803424
33813425845
3382342600:42:51,502 --> 00:42:54,870
33833427that's what it does. But that is not the case here. This one
3428+ 这就是他的工作。但我们这里不是这样的情况。这里
33843429
33853430846
3386343100:42:54,939 --> 00:42:58,240
33873432wants to be private. And the reason it wants to be private
3433+ 我们想要是 private 的。它应该是私有的
33883434
33893435847
3390343600:42:58,309 --> 00:43:01,477
33913437is because the number of pairs of cards in the game is
3438+ 原因是 numberOfPairsOfCards
33923439
33933440848
3394344100:43:01,545 --> 00:43:04,480
33953442intimately tied to the UI, okay the number of
3443+ 游戏里卡片的对数是和 UI 捆绑着的
33963444
33973445849
3398344600:43:04,549 --> 00:43:07,083
33993447cards we have in the UI. So if we wanted to make
3448+ 是我们 UI 理由的卡的对数。如果我们想要
34003449
34013450850
3402345100:43:07,151 --> 00:43:09,585
34033452this public then we'd also have to make something public
3453+ 让它公开的的话,我们也需要让另一个公开的
34043454
34053455851
3406345600:43:09,653 --> 00:43:13,356
34073457to specify the number of card buttons that we allow and
3458+ 来指定我们允许的显示卡片的按钮的个数
34083459
34093460852
3410346100:43:13,425 --> 00:43:15,391
34113462we don't do that currently,
3463+ 但我们现在并不是这样的
34123464
34133465853
3414346600:43:15,460 --> 00:43:18,127
34153467that's something that is in our little scene and
3468+ 那现在是我们在 Interface Builder
34163469
34173470854
3418347100:43:18,195 --> 00:43:21,430
34193472interface builder, so we don't do it. So we keep this, we
3473+ 的场景里设置的,所以我们不这样做。所以我们保持这个
34203474
34213475855
3422347600:43:21,499 --> 00:43:25,067
34233477keep this private. How about number of pairs of cards?
3478+ 让他就是 private 的。那 numberOfPairsOfCards 呢?
34243479
34253480856
3426348100:43:25,136 --> 00:43:28,271
0 commit comments