Skip to content

Commit c6ce132

Browse files
committed
翻译 4 集 999-1040 和 1299
1 parent 17fd505 commit c6ce132

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

subtitles/4. More Swift.srt

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4992,172 +4992,212 @@ show you an interesting thing about one of them.
49924992
999
49934993
00:52:11,495 --> 00:52:16,265
49944994
So here is replace range, which, my pointer doesn't work
4995-
这是 replaceSubrange 啊我的笔用不了了
4995+
这是 replaceSubrange。啊我的控制器用不了了
49964996

49974997
1000
49984998
00:52:16,333 --> 00:52:18,133
49994999
any more, but if you look at replace range,
5000-
那你看一下 replaceSubrange 那里
5000+
但你看一下 replaceSubrange 那里
50015001

50025002
1001
50035003
00:52:18,201 --> 00:52:21,069
50045004
do you see where it's red, right there? That's that dot,
5005+
看到红色的这个吗?那个
50055006

50065007
1002
50075008
00:52:21,138 --> 00:52:23,905
50085009
dot less than thing, look, I forgot to put something on
5010+
点点小于富豪,我是不是忘了放点东西
50095011

50105012
1003
50115013
00:52:23,974 --> 00:52:28,076
50125014
the left. So what does that range go from? Okay,
5015+
在左边?那这个区间是从哪里开始的呢?
50135016

50145017
1004
50155018
00:52:28,145 --> 00:52:31,613
50165019
we know it goes to s.endIndex. Well, Swift is smart enough to
5020+
但我们知道它是在 s.endIndex 结束。其实 Swift 很聪明
50175021

50185022
1005
50195023
00:52:31,682 --> 00:52:35,150
50205024
know that that is a range of str-, the strings indexes,
5025+
知道这是这个字符串的索引
50215026

50225027
1006
50235028
00:52:35,219 --> 00:52:38,854
50245029
so it will automatically put start index at the beginning.
5030+
所以它会自动认为开始的索引是在字符串的开头
50255031

50265032
1007
50275033
00:52:38,923 --> 00:52:40,155
50285034
And if you left off the other side,
5035+
如果你是只省略右边的话
50295036

50305037
1008
50315038
00:52:40,224 --> 00:52:43,659
50325039
it will automatically put ending index at the end. So
5040+
它会自动把字符串的结尾当作结束的索引
50335041

50345042
1009
50355043
00:52:43,728 --> 00:52:46,228
50365044
you can oh, leave those arranged things open ended.
5045+
也就是,你可以省略其中一个的边界
50375046

50385047
1010
50395048
00:52:46,297 --> 00:52:48,764
50405049
But Swift has to be able to infer the type of whats going
5050+
但 Swift 得先要能够判断发生了什么
50415051

50425052
1011
50435053
00:52:48,833 --> 00:52:50,065
50445054
on there. So you can't always do it,
5055+
所以你并不总是这样做
50455056

50465057
1012
50475058
00:52:50,134 --> 00:52:53,702
50485059
but in that case you could. Okay, so
5060+
但这里你是可以的。好
50495061

50505062
1013
50515063
00:52:53,771 --> 00:52:58,274
50525064
that's string. I guess we'll go like this. So, to
5065+
这就是字符串,就讲到这里。
50535066

50545067
1014
50555068
00:52:58,342 --> 00:53:02,611
50565069
make this all understandable let's go back to our,
5070+
为了让这个更容易理解,我们回到我们的
50575071

50585072
1015
50595073
00:53:02,679 --> 00:53:08,249
50605074
um, concentration. And we're gonna make this
5075+
Concentration 里,我们要把这个
50615076

50625077
1016
50635078
00:53:08,318 --> 00:53:12,421
50645079
thing right here, this emoji choices,
5080+
这里这个 emojiChoices
50655081

50665082
1017
50675083
00:53:12,489 --> 00:53:15,424
50685084
which is currently an array of emoji strings.
5085+
它现在是一个表情字符串的数组
50695086

50705087
1018
50715088
00:53:15,492 --> 00:53:17,759
50725089
I'm gonna change that. I'm gonna copy and paste it here.
5090+
我要把它改掉,我复制粘贴一下
50735091

50745092
1019
50755093
00:53:17,828 --> 00:53:21,730
50765094
I'm gonna change it from being an array, to being a string.
5095+
我把它从数组改为字符串
50775096

50785097
1020
50795098
00:53:21,799 --> 00:53:24,433
50805099
So I'm gonna take off the array things.
5100+
所以我把数组的这些先去掉
50815101

50825102
1021
50835103
00:53:24,501 --> 00:53:29,304
50845104
And I'm gonna get rid of all of these little commas. And
5105+
我去掉这些逗号
50855106

50865107
1022
50875108
00:53:29,373 --> 00:53:32,707
50885109
now emojiChoices is gonna be a string.
5110+
现在 emojiChoices 就是个字符串了
50895111

50905112
1023
50915113
00:53:32,776 --> 00:53:35,577
50925114
And I'm gonna have my code be the same,
5115+
我就保持代码不变
50935116

50945117
1024
50955118
00:53:35,646 --> 00:53:38,179
50965119
but instead of grab it out of the array, it's gonna grab it
5120+
但不从数组里取值了。我获得这些值
50975121

50985122
1025
50995123
00:53:38,248 --> 00:53:41,250
51005124
out of the string. Now as soon as I change that to a string,
5125+
改成从字符串里。现在我把它改成字符串之后
51015126

51025127
1026
51035128
00:53:41,319 --> 00:53:44,853
51045129
look what happens. Cannot convert value of type
5130+
你看会发生什么?不能转换类型为 Int 的值
51055131

51065132
1027
51075133
00:53:44,921 --> 00:53:49,625
51085134
int to expected argument, string.index. Okay, remove at,
5135+
为期待的参数类型 String.Index。好吧,remove(at:)
51095136

51105137
1028
51115138
00:53:49,694 --> 00:53:52,027
51125139
right here, which we moved to remove the thing,
5140+
就这个,我们用来移除表情的
51135141

51145142
1029
51155143
00:53:52,095 --> 00:53:57,365
51165144
where do you think that's declared? Anyone wanna guess?
5145+
你认为这个方法是在哪里定义的?有谁想猜一下吗?
51175146

51185147
1030
51195148
00:53:57,434 --> 00:54:02,437
51205149
Is that an array thing? A string? No,
5150+
那是 Array 类的吗?还是 String 的?不
51215151

51225152
1031
51235153
00:54:02,506 --> 00:54:04,973
51245154
that's in collection, range replaceable collection, right?
5155+
它是 RangeReplaceableCollection 实现的
51255156

51265157
1032
51275158
00:54:05,042 --> 00:54:07,142
51285159
So it's in a protocol somewhere that both string and
5160+
是在这个 protocol 里某个地方,而且 String
51295161

51305162
1033
51315163
00:54:07,211 --> 00:54:07,976
51325164
array implement. So
5165+
和 Array 的遵守了这个协议。所以
51335166

51345167
1034
51355168
00:54:08,045 --> 00:54:10,178
51365169
you would think it should just work here,
5170+
你会认为这个应该可以直接行得通
51375171

51385172
1035
51395173
00:54:10,247 --> 00:54:13,315
51405174
because emoji choices, yeah, now it's a string, but remove
5175+
因为 emojiChoices 只不过现在变成了字符串,即使
51415176

51425177
1036
51435178
00:54:13,384 --> 00:54:15,884
51445179
at is in range replaceable collection, they're range
5180+
remove(at:) 是 RangeReplaceableCollection 里定义的
51455181

51465182
1037
51475183
00:54:15,952 --> 00:54:18,454
51485184
replaceable collection. Why does this work? Well,
5185+
但它们也都遵守这个协议,为什么这个行不通?
51495186

51505187
1038
51515188
00:54:18,522 --> 00:54:21,823
51525189
because strings are not indexed by ints. And
5190+
因为字符串不是靠 Int 索引的
51535191

51545192
1039
51555193
00:54:21,892 --> 00:54:25,494
51565194
so this doesn't work. So we have to create a string.index,
5195+
所以这个不能用。我们必须构造一个 String.Index
51575196

51585197
1040
51595198
00:54:25,562 --> 00:54:29,465
51605199
I'm gonna do that. I'm gonna create a random string index
5200+
那我就这样做,创建一个随机的字符串索引
51615201

51625202
1041
51635203
00:54:29,533 --> 00:54:34,002
@@ -6194,6 +6234,7 @@ I'm gonna assign operation = sqrt. Okay,
61946234
1299
61956235
01:08:12,922 --> 01:08:16,724
61966236
sqrt is a function that takes a double and returns a double.
6237+
sqrt 是个函数,接受一个 Double,返回一个 Double
61976238

61986239
1300
61996240
01:08:16,792 --> 01:08:20,161

0 commit comments

Comments
 (0)