Skip to content

Commit e70557c

Browse files
authored
Merge pull request #51 from yanqizhao/feature/lecture_2_151-200
翻译第 2 集 151 - 200 条字幕
2 parents 400ad97 + e9b00d3 commit e70557c

File tree

2 files changed

+55
-72
lines changed

2 files changed

+55
-72
lines changed

subtitles/en/Lecture 2. MVVM and the Swift Type System.srt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ between the Model and the View.
835835

836836
188
837837
00:08:41,960 --> 00:08:44,750
838-
It's gonna be the thing that
838+
It's going be the thing that
839839

840840
189
841841
00:08:44,750 --> 00:08:48,020

subtitles/zh-Hans/Lecture 2. MVVM and the Swift Type System.srt

Lines changed: 54 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -621,224 +621,207 @@ Text 和 HStack
621621

622622
151
623623
00:07:05,290 --> 00:07:07,420
624-
At any time you should be able to say
624+
任何时刻你都可以让视图
625625

626626
152
627627
00:07:07,420 --> 00:07:09,030
628-
make it look like the Model
628+
按照模型中的数据来显示
629629

630630
153
631631
00:07:09,030 --> 00:07:11,900
632-
and so, we are gonna have a system
632+
在 Swift 中有一种机制
633633

634634
154
635635
00:07:11,900 --> 00:07:13,530
636-
where whenever the Model changes,
636+
可以在模型发生变化时
637637

638638
155
639639
00:07:13,530 --> 00:07:16,700
640-
it asks the View to look
641-
like it automatically.
640+
自动更新视图
642641

643642
156
644643
00:07:16,700 --> 00:07:18,690
645-
Call that reactive programming,
644+
叫做响应式编程
646645

647646
157
648647
00:07:18,690 --> 00:07:22,410
649-
it's reacting to changes in the Model.
648+
它会对模型中的变化作出响应
650649

651650
158
652651
00:07:22,410 --> 00:07:23,470
653-
So that's it.
652+
就是这样一种机制
654653

655654
159
656655
00:07:23,470 --> 00:07:26,303
657-
This is what we got to make happen
656+
我们引入视图模型(ViewModel)
658657

659658
160
660659
00:07:27,980 --> 00:07:32,980
661-
is it introduces another
662-
thing called the ViewModel.
660+
来实现这种机制
663661

664662
161
665663
00:07:33,044 --> 00:07:36,870
666-
The ViewModel's job is to
667-
bind the View to the Model.
664+
视图模型的工作就是将视图
665+
绑定到对应的模型上
668666

669667
162
670668
00:07:36,870 --> 00:07:38,940
671-
So the one change has
672-
happened in the Model,
669+
模型中的数据一旦发生变化
673670

674671
163
675672
00:07:38,940 --> 00:07:41,530
676-
the View get reflected.
673+
视图就会对其作出响应
677674

678675
164
679676
00:07:41,530 --> 00:07:43,130
680-
And along the way,
677+
在视图模型
681678

682679
165
683680
00:07:43,130 --> 00:07:45,920
684-
as it does that binding
685-
between the Model and the View,
681+
对模型和视图进行绑定的过程中
686682

687683
166
688684
00:07:45,920 --> 00:07:49,150
689-
it might be interpreting
690-
the Model for the View
685+
会将模型中的数据转换为
686+
视图可以理解的形式
691687

692688
167
693689
00:07:49,150 --> 00:07:50,980
694-
because we want the View to be very simple
690+
因为我们希望在声明式编程中
695691

696692
168
697693
00:07:50,980 --> 00:07:53,870
698-
since we're writing it
699-
in a declarative way,
694+
视图能够尽量简洁
700695

701696
169
702697
00:07:53,870 --> 00:07:55,790
703-
we don't want it to have
704-
a lot of code in there
698+
我们不希望视图中的代码过多
705699

706700
170
707701
00:07:55,790 --> 00:07:58,750
708-
that's like converting from
709-
one data type to another
702+
例如数据类型转换之类的工作
710703

711704
171
712705
00:07:58,750 --> 00:07:59,770
713-
and things like that.
706+
都不要交给视图
714707

715708
172
716709
00:07:59,770 --> 00:08:02,320
717-
So we're gonna ask the
718-
ViewModel to do that.
710+
而是交给视图模型去做
719711

720712
173
721713
00:08:02,320 --> 00:08:05,480
722-
Our Model in our game
723-
that we're writing here,
714+
我们这里构建的记忆游戏中的模型
724715

725716
174
726717
00:08:05,480 --> 00:08:08,150
727-
this memory game, our Model
728-
is just gonna be a struct.
718+
是一个结构体
729719

730720
175
731721
00:08:08,150 --> 00:08:10,130
732-
This is a very simple little demo
722+
这是一个非常简单的示例程序
733723

734724
176
735725
00:08:10,130 --> 00:08:11,940
736-
but you could imagine that your Model
726+
但是你可以设想这里的模型
737727

738728
177
739729
00:08:11,940 --> 00:08:15,560
740-
is a SQL database or it's
741-
something over the network
730+
是一个 SQL 数据库,或是向网络发出的
742731

743732
178
744733
00:08:15,560 --> 00:08:17,610
745-
where you're making HTTP requests.
734+
HTTP 请求
746735

747736
179
748737
00:08:17,610 --> 00:08:19,760
749-
So it can be quite complicated over there
738+
这样的模型就相当复杂了
750739

751740
180
752741
00:08:19,760 --> 00:08:22,460
753-
and your ViewModel can simplify that,
742+
视图模型可以将其封装到
754743

755744
181
756745
00:08:22,460 --> 00:08:25,080
757-
boil it down into maybe
758-
some simpler data structures
746+
更简洁的数据结构中
759747

760748
182
761749
00:08:25,080 --> 00:08:27,420
762-
that it can pass to the View
750+
之后再传递给视图
763751

764752
183
765753
00:08:27,420 --> 00:08:30,340
766-
that will let the View be
767-
simple code that draws it.
754+
这样视图中就只有实现绘制的代码了
768755

769756
184
770757
00:08:30,340 --> 00:08:32,760
771-
So, the ViewModel does
772-
have this role a little bit
758+
视图模型在这里扮演的角色
773759

774760
185
775761
00:08:32,760 --> 00:08:36,053
776-
as an interpreter of that Model data.
762+
就像一个模型数据的解释者
777763

778764
186
779765
00:08:36,990 --> 00:08:40,101
780-
So we're gonna interpose the ViewModel
766+
这样我们就引入了介于模型和视图
781767

782768
187
783769
00:08:40,101 --> 00:08:41,960
784-
between the Model and the View.
770+
之间的视图模型
785771

786772
188
787773
00:08:41,960 --> 00:08:44,750
788-
It's gonna be the thing that
774+
它帮助视图实现
789775

790776
189
791777
00:08:44,750 --> 00:08:48,020
792-
helps make this automatic
793-
updating happening.
778+
自动更新
794779

795780
190
796781
00:08:48,020 --> 00:08:50,430
797-
So how does it do what it does?
782+
那么它是如何做到的呢?
798783

799784
191
800785
00:08:50,430 --> 00:08:51,890
801-
Well, first of all the ViewModel
786+
首先,视图模型
802787

803788
192
804789
00:08:51,890 --> 00:08:54,710
805-
is always trying to notice
806-
changes in the Model
790+
会随时关注模型的变化
807791

808792
193
809793
00:08:54,710 --> 00:08:57,390
810-
and it can do that any way that it wants.
794+
它可以通过任何方式实现
811795

812796
194
813797
00:08:57,390 --> 00:09:00,900
814-
If your Model is a struct,
815-
it's actually quite easy.
798+
如果你的模型是一个结构体
799+
那相当容易
816800

817801
195
818802
00:09:00,900 --> 00:09:02,600
819-
Again, I'm gonna talk about a struct,
803+
我又一次谈到了结构体
820804

821805
196
822806
00:09:02,600 --> 00:09:05,450
823-
more about that type in
824-
Swift in a few moments
807+
之后还会讲到更多关于 Swift 中
808+
结构体这个类型的特性
825809

826810
197
827811
00:09:05,450 --> 00:09:07,980
828-
but one great feature of a struct
812+
其中一个重要的特性是
829813

830814
198
831815
00:09:07,980 --> 00:09:09,460
832-
since it's copied around
816+
因为将结构体
833817

834818
199
835819
00:09:09,460 --> 00:09:11,431
836-
when it's passed to functions and stuff
820+
传递给函数时会被复制一份
837821

838822
200
839823
00:09:11,431 --> 00:09:15,030
840-
is that Swift knows when
841-
a struct has changed.
824+
所以 Swift 知道结构体发生变化的时机
842825

843826
201
844827
00:09:15,030 --> 00:09:16,998

0 commit comments

Comments
 (0)