@@ -4992,172 +4992,212 @@ show you an interesting thing about one of them.
49924992999
4993499300:52:11,495 --> 00:52:16,265
49944994So here is replace range, which, my pointer doesn't work
4995- 这是 replaceSubrange 啊我的笔用不了了
4995+ 这是 replaceSubrange。啊我的控制器用不了了
49964996
499749971000
4998499800:52:16,333 --> 00:52:18,133
49994999any more, but if you look at replace range,
5000- 那你看一下 replaceSubrange 那里
5000+ 但你看一下 replaceSubrange 那里
50015001
500250021001
5003500300:52:18,201 --> 00:52:21,069
50045004do you see where it's red, right there? That's that dot,
5005+ 看到红色的这个吗?那个
50055006
500650071002
5007500800:52:21,138 --> 00:52:23,905
50085009dot less than thing, look, I forgot to put something on
5010+ 点点小于富豪,我是不是忘了放点东西
50095011
501050121003
5011501300:52:23,974 --> 00:52:28,076
50125014the left. So what does that range go from? Okay,
5015+ 在左边?那这个区间是从哪里开始的呢?
50135016
501450171004
5015501800:52:28,145 --> 00:52:31,613
50165019we know it goes to s.endIndex. Well, Swift is smart enough to
5020+ 但我们知道它是在 s.endIndex 结束。其实 Swift 很聪明
50175021
501850221005
5019502300:52:31,682 --> 00:52:35,150
50205024know that that is a range of str-, the strings indexes,
5025+ 知道这是这个字符串的索引
50215026
502250271006
5023502800:52:35,219 --> 00:52:38,854
50245029so it will automatically put start index at the beginning.
5030+ 所以它会自动认为开始的索引是在字符串的开头
50255031
502650321007
5027503300:52:38,923 --> 00:52:40,155
50285034And if you left off the other side,
5035+ 如果你是只省略右边的话
50295036
503050371008
5031503800:52:40,224 --> 00:52:43,659
50325039it will automatically put ending index at the end. So
5040+ 它会自动把字符串的结尾当作结束的索引
50335041
503450421009
5035504300:52:43,728 --> 00:52:46,228
50365044you can oh, leave those arranged things open ended.
5045+ 也就是,你可以省略其中一个的边界
50375046
503850471010
5039504800:52:46,297 --> 00:52:48,764
50405049But Swift has to be able to infer the type of whats going
5050+ 但 Swift 得先要能够判断发生了什么
50415051
504250521011
5043505300:52:48,833 --> 00:52:50,065
50445054on there. So you can't always do it,
5055+ 所以你并不总是这样做
50455056
504650571012
5047505800:52:50,134 --> 00:52:53,702
50485059but in that case you could. Okay, so
5060+ 但这里你是可以的。好
50495061
505050621013
5051506300:52:53,771 --> 00:52:58,274
50525064that's string. I guess we'll go like this. So, to
5065+ 这就是字符串,就讲到这里。
50535066
505450671014
5055506800:52:58,342 --> 00:53:02,611
50565069make this all understandable let's go back to our,
5070+ 为了让这个更容易理解,我们回到我们的
50575071
505850721015
5059507300:53:02,679 --> 00:53:08,249
50605074um, concentration. And we're gonna make this
5075+ Concentration 里,我们要把这个
50615076
506250771016
5063507800:53:08,318 --> 00:53:12,421
50645079thing right here, this emoji choices,
5080+ 这里这个 emojiChoices
50655081
506650821017
5067508300:53:12,489 --> 00:53:15,424
50685084which is currently an array of emoji strings.
5085+ 它现在是一个表情字符串的数组
50695086
507050871018
5071508800:53:15,492 --> 00:53:17,759
50725089I'm gonna change that. I'm gonna copy and paste it here.
5090+ 我要把它改掉,我复制粘贴一下
50735091
507450921019
5075509300:53:17,828 --> 00:53:21,730
50765094I'm gonna change it from being an array, to being a string.
5095+ 我把它从数组改为字符串
50775096
507850971020
5079509800:53:21,799 --> 00:53:24,433
50805099So I'm gonna take off the array things.
5100+ 所以我把数组的这些先去掉
50815101
508251021021
5083510300:53:24,501 --> 00:53:29,304
50845104And I'm gonna get rid of all of these little commas. And
5105+ 我去掉这些逗号
50855106
508651071022
5087510800:53:29,373 --> 00:53:32,707
50885109now emojiChoices is gonna be a string.
5110+ 现在 emojiChoices 就是个字符串了
50895111
509051121023
5091511300:53:32,776 --> 00:53:35,577
50925114And I'm gonna have my code be the same,
5115+ 我就保持代码不变
50935116
509451171024
5095511800:53:35,646 --> 00:53:38,179
50965119but instead of grab it out of the array, it's gonna grab it
5120+ 但不从数组里取值了。我获得这些值
50975121
509851221025
5099512300:53:38,248 --> 00:53:41,250
51005124out of the string. Now as soon as I change that to a string,
5125+ 改成从字符串里。现在我把它改成字符串之后
51015126
510251271026
5103512800:53:41,319 --> 00:53:44,853
51045129look what happens. Cannot convert value of type
5130+ 你看会发生什么?不能转换类型为 Int 的值
51055131
510651321027
5107513300:53:44,921 --> 00:53:49,625
51085134int to expected argument, string.index. Okay, remove at,
5135+ 为期待的参数类型 String.Index。好吧,remove( at:)
51095136
511051371028
5111513800:53:49,694 --> 00:53:52,027
51125139right here, which we moved to remove the thing,
5140+ 就这个,我们用来移除表情的
51135141
511451421029
5115514300:53:52,095 --> 00:53:57,365
51165144where do you think that's declared? Anyone wanna guess?
5145+ 你认为这个方法是在哪里定义的?有谁想猜一下吗?
51175146
511851471030
5119514800:53:57,434 --> 00:54:02,437
51205149Is that an array thing? A string? No,
5150+ 那是 Array 类的吗?还是 String 的?不
51215151
512251521031
5123515300:54:02,506 --> 00:54:04,973
51245154that's in collection, range replaceable collection, right?
5155+ 它是 RangeReplaceableCollection 实现的
51255156
512651571032
5127515800:54:05,042 --> 00:54:07,142
51285159So it's in a protocol somewhere that both string and
5160+ 是在这个 protocol 里某个地方,而且 String
51295161
513051621033
5131516300:54:07,211 --> 00:54:07,976
51325164array implement. So
5165+ 和 Array 的遵守了这个协议。所以
51335166
513451671034
5135516800:54:08,045 --> 00:54:10,178
51365169you would think it should just work here,
5170+ 你会认为这个应该可以直接行得通
51375171
513851721035
5139517300:54:10,247 --> 00:54:13,315
51405174because emoji choices, yeah, now it's a string, but remove
5175+ 因为 emojiChoices 只不过现在变成了字符串,即使
51415176
514251771036
5143517800:54:13,384 --> 00:54:15,884
51445179at is in range replaceable collection, they're range
5180+ remove( at:) 是 RangeReplaceableCollection 里定义的
51455181
514651821037
5147518300:54:15,952 --> 00:54:18,454
51485184replaceable collection. Why does this work? Well,
5185+ 但它们也都遵守这个协议,为什么这个行不通?
51495186
515051871038
5151518800:54:18,522 --> 00:54:21,823
51525189because strings are not indexed by ints. And
5190+ 因为字符串不是靠 Int 索引的
51535191
515451921039
5155519300:54:21,892 --> 00:54:25,494
51565194so this doesn't work. So we have to create a string.index,
5195+ 所以这个不能用。我们必须构造一个 String.Index
51575196
515851971040
5159519800:54:25,562 --> 00:54:29,465
51605199I'm gonna do that. I'm gonna create a random string index
5200+ 那我就这样做,创建一个随机的字符串索引
51615201
516252021041
5163520300:54:29,533 --> 00:54:34,002
@@ -6194,6 +6234,7 @@ I'm gonna assign operation = sqrt. Okay,
619462341299
6195623501:08:12,922 --> 01:08:16,724
61966236sqrt is a function that takes a double and returns a double.
6237+ sqrt 是个函数,接受一个 Double,返回一个 Double
61976238
619862391300
6199624001:08:16,792 --> 01:08:20,161
0 commit comments