1. Mutability of Collections
集合的可变性
2. For dictionaries, immutability also mean that you cannot replace the value for an existing key in the dictionary .
对字典来说,不可变性也意味这我们不能替换其中任何现有键所对应的值。
3. This enables Swift’s array type to provide optimal performance for array operations when the size an array is fixed.
这使得swift数组在大小被固定的时候依然可以做得很棒。
4. The collection of items being iterated is a closed range of numbers from 1 to 5 inclusive , as indicated by the use of the closed range operator (…).
例子中用来进行便利的元素是一组使用闭区间操作符(…)表示从1到5的闭区间数字。
5. In the example above ,index is a constant whose value is automatically set at the start of each iteration of the loop . As such , it does not to be declared before it is used . It is implicitly declared simply by its inclusion in the loop declaration , without the need for a let declaration keyword.
上面的例子中,index 是一个每次循环便利开始时被自动赋值的常量。这种情况下,index在使用前不需要声明,只需要將它包含在循环的声明中,就可以对其进行隐式声明,而无需使用let关键字声明。
6. If you do not need each value from the range ,you can ignore the values by using an underscore in place of a variable name:
如果你不需要知道范围内每一项的值,你可以使用下划线(-)替代变量名来忽略访对值的访问:
7. retrieve 检索、恢复
8. Semicolons separate the three parts of the loop’s definition, as in C . however , unlike C ,
Swift doesn’t need to parentheses around the entire “initialization ; condition; increment” block.
Semicolons 分号
Parentheses 园括号
和C语言一样,分号將循环的定义分为3个部分,不同的是,Swift不需要使用圆括号將“初始条件,条件,增加”包括起来。
9. evaluated 评价、评估
10. increment expression递增表达式
11.This example uses a very simple approach to dice rolling.
本例中使用了最简单的方法来模拟投骰子。
combination | |
[英]ˌkɒmbɪˈneɪʃn | [美]ˌkɑ:mbɪˈneɪʃn |
n. | (一组事物可能的一种)序列,排列,排列中的任一组数字或文字 |
n. | 结合;联合体;密码组合;连裤内衣 |
Swift provides two ways to add conditional branches to your code,known as the if statement and switch statement .Typically, you use the if statement to evaluate simple conditions with only a few possible outcomes. The switch statement is
better suited to more complex conditions with multiple possible permutations,and is
useful in situations where pattern-matching can help select an appropriate code branch to execute.
Switch 提供两种类型的条件语句:if语句和switch语句。通常,当条件较为简单且可能的情况很少时,使用if语句。而switch语句更适合用于复杂的条件,可能的情况很多且需要用到模式匹配的情景。
n. | 围巾,领巾;嵌接;桌巾,台巾;(木材,金属,皮革的)嵌接 |
v. | 围(围巾);打(领带);披(披巾);用围巾[台布]围[盖] |
exclude | [英]ɪkˈsklu:d | [美]ɪk'sklu:d |
vt. | 排除,不包括;排斥;驱除,赶出 |
adj. | 彻底的,透彻的;消耗的,使枯竭的;详尽的,无遗的;详尽无遗 |
逃出 |
diagonal line 对角线
As in the previous example , the final case matches all possible remaining values. and so a default case is not needed to make the switch statement exhaustive.
在前面的例子汇总,由于最后一个case块中匹配了余下所有的可能值,switch语句已经完备了,因此不需要书写默认块。
control transfer statements. 条件转移语句
cryptic puzzle phrase 含义模糊的语句
catchall | [英]'kætʃɔ:l | [美]'kætʃˌɔ:l |
n. | 放各种各样物品的容器,包罗甚广的话(或法律等),装零杂物品的容器 |
adj. | 包罗万象的 |
Labeled Statement 标签语句
You can nest loops and switch stements inside other loops and switch staement in Swift to create complex control flow structures.
在swift语言中你可在循环体和switch代码快中嵌套使用循环体和switch代码块来创造复杂的控制流结构。
functions are self-contained chunks of code that perform a specific task.
函数是执行特定任务的代码只包含块。
Strictly speaking, the sayGoodbye function does still return a value,even though no
return value is defined . Function without a defined return type return a special value of type Void.
严格来说,sayGoodbye函数确实有一个返回值,即使没有定义返回值。没有定义返回类型的函数返回一个void类型的特殊值。
Founctioon with Multiple Return Values
多返回值函数
Founction Parameter Names
函数形参
Local parameter name
本地形参名
ambiguity | |
[英]ˌæmbɪˈgju:əti | [美]ˌæmbɪˈɡjuɪti |
n. | 含糊;意义不明确;含糊的话,模棱两可的话;可作两种或多种解释 |
adj. | 含糊的,不明确的;引起歧义的;有两种或多种意思的; |
The function‘s choice of parameter makes for a clear,readable function body,
while also enable tne function to be called without ambiguilty:
该函数对形参名的选择使得函数主体更加清晰易读,并且在调用该函数的时候也不会有歧义: