词表 · 第 9 篇
Swift
1. infix
- 译:中缀 | Swift:运算符位于两个操作数之间的形式(如 + - *)
- 例
- Swift lets you declare custom infix operators. — Swift 允许你声明自定义中缀运算符。
- Infix operators go between their operands. — 中缀运算符位于两个操作数之间。
- 地道:infix notation(中缀表示法)
- 短语:infix operator · precedence group · associativity
2. prefix
- 译:前缀 | Swift:运算符写在操作数之前的形式(如 ! -)
- 例
- The prefix ! negates a Bool. — 前缀 ! 对布尔值取反。
- You can declare a custom prefix operator. — 你可以声明自定义前缀运算符。
- 地道:prefix operator(前缀运算符)
- 短语:prefix operator · prefix notation · prefix -
3. postfix
- 译:后缀 | Swift:运算符跟在操作数之后的形式(如 ! 强制解包)
- 例
- The postfix ! force-unwraps an optional. — 后缀 ! 强制解包可选值。
- Postfix operators follow their operand. — 后缀运算符跟在操作数之后。
- 地道:postfix operator(后缀运算符)
- 短语:postfix operator · force-unwrap · postfix !
4. unary
- 译:一元的 | Swift:只有一个操作数的运算符(前缀或后缀)
- 例
- The unary minus negates a number. — 一元减号对数字取负。
- Swift splits unary operators into prefix and postfix. — Swift 把一元运算符分为前缀和后缀两类。
- 地道:unary operator(一元运算符)
- 短语:unary operator · unary minus · binary operator
5. overflow
- 译:溢出 | Swift:值超出类型可表示范围;提供 &+ &- &* 溢出运算符
- 例
- Use &+ to allow overflow. — 用 &+ 允许溢出。
- Arithmetic overflow traps by default in Swift. — Swift 默认对算术溢出触发陷阱。
- 地道:overflow operator(溢出运算符)
- 短语:overflow operator · &+ &- &* · arithmetic overflow
6. guard
- 译:守卫;guard 语句 | Swift:要求条件成立否则提前退出的控制流语句
- 例
- Use guard to bail out early. — 用 guard 提前退出。
- guard let safely unwraps optionals. — guard let 安全地解包可选值。
- 地道:guard let else(guard 解包)
- 短语:guard let · guard else · early exit
7. bitwise
- 译:按位的 | Swift:对整数二进制位逐位运算(& | ^ ~ << >>)
- 例
- Bitwise AND is written as & in Swift. — 按位与在 Swift 中写作 &。
- Use bitwise operators for flag masks. — 用按位运算符处理标志位掩码。
- 地道:bitwise operator(按位运算符)
- 短语:bitwise AND · bitwise OR · bitwise shift
8. extension
- 译:扩展 | Swift:向已有类型追加方法、计算属性或协议一致性
- 例
- Add methods to existing types via extension. — 通过 extension 给已有类型添加方法。
- Conform to a protocol in an extension. — 在 extension 中遵循协议。
- 地道:extend a type(扩展一个类型)
- 短语:extension on · retroactive conformance · protocol conformance
9. protocol
- 译:协议 | Swift:声明方法/属性要求、由类型 conform 实现的契约
- 例
- A protocol declares requirements. — 协议声明一组要求。
- Conform to a protocol to satisfy its contract. — 遵循协议以满足其契约。
- 地道:protocol-oriented programming(面向协议编程)
- 短语:protocol conformance · associated type · protocol witness
10. internal
- 译:内部的 | Swift:模块内可见的默认访问级别
- 例
- internal is the default access level. — internal 是默认访问级别。
- internal types are visible across files in the module. — internal 类型在模块内跨文件可见。
- 地道:module-internal(模块内部)
- 短语:internal access · access level · file-private vs internal
11. clause
- 译:子句 | Swift:语句中的条件/约束片段(如 where clause)
- 例
- The where clause constrains associated types. — where 子句约束关联类型。
- A generic where clause refines type relationships. — 泛型 where 子句细化类型关系。
- 地道:where clause(where 子句)
- 短语:where clause · generic where clause · catch clause
12. constraint
- 译:约束 | Swift:泛型对类型参数施加的要求(protocol 一致性或 where clause)
- 短语:generic constraint · type constraint · where clause
13. optional
- 译:可选的;可选类型 | Swift:表示值存在或为 nil 的类型(T?)
- 例
- An optional either holds a value or nil. — 可选值要么持有值要么为 nil。
- Use optional binding to unwrap safely. — 用可选绑定安全解包。
- 地道:optional unwrapping(可选解包)
- 短语:optional type · optional binding · force-unwrap
14. closures
- 译:闭包(closure 的复数)| Swift:自包含、可捕获上下文变量的功能块
- 例
- Closures capture surrounding variables. — 闭包会捕获周围变量。
- Trailing closure syntax reads cleanly. — 尾随闭包语法读起来很清爽。
- 地道:trailing closure(尾随闭包)
- 短语:trailing closure · escaping closure · capture list
15. actor
- 译:actor | Swift:自行串行隔离可变状态、用于并发安全的引用类型
- 例
- An actor serializes access to its state. — actor 串行化对其状态的访问。
- Use actors to share mutable state safely. — 用 actor 安全地共享可变状态。
- 地道:actor isolation(actor 隔离)
- 短语:actor isolation · nonisolated · MainActor
16. ARC
- 译:ARC(Automatic Reference Counting,自动引用计数)| Swift:编译器自动插入引用计数代码管理引用类型内存
- 例
- ARC tracks reference counts at compile time. — ARC 在编译期跟踪引用计数。
- Strong references can cause retain cycles. — 强引用可能造成循环引用。
- 地道:retain cycle(循环引用)
- 短语:strong / weak / unowned · retain cycle · reference counting
17. async
- 译:异步的;async 函数 | Swift:标记可使用 await 挂起的函数
- 例
- Mark a function async to use await inside. — 把函数标记为 async 才能在内部使用 await。
- async functions can run concurrently when awaited. — 被 await 时 async 函数可以并发执行。
- 地道:async/await(异步/等待)
- 短语:async function · async let · async sequence
18. await
- 译:等待;await | Swift:暂停异步函数直到被等待的任务完成
- 例
- await suspends until the task finishes. — await 挂起直到任务完成。
- Use await only inside async contexts. — await 只能在 async 上下文中使用。
- 地道:await a result(等待结果)
- 短语:await · async/await · structured concurrency
19. class
- 译:类(Swift:可继承的引用类型)
- 短语:class inheritance · subclass · reference type
20. enum
- 译:枚举 | Swift:定义一组相关值的值类型,支持关联值与原始值
- 例
- enum defines a group of related values. — enum 定义一组相关值。
- Associated values make enums powerful. — 关联值让 enum 变得强大。
- 地道:associated value(关联值)
- 短语:enum case · associated value · raw value
21. generic
- 译:泛型的;通用的 | Swift:以类型参数编写、复用与类型安全兼得(func f
()) - 短语:generic function · generic type · type parameter
22. initializer
- 译:初始化器 | Swift:构造类型实例的特殊方法(init)
- 例
- The designated initializer is the primary init. — 指定初始化器是主要的 init。
- Convenience initializers delegate across. — 便利初始化器横向委托。
- 地道:designated initializer(指定初始化器)
- 短语:designated initializer · convenience initializer · failable initializer
23. mutating
- 译:变异的;mutating 方法 | Swift:标记可修改值类型 self 的方法
- 例
- Mark a method mutating to modify self. — 把方法标记为 mutating 才能修改 self。
- struct methods need mutating to change properties. — struct 的方法需要 mutating 才能修改属性。
- 地道:mutating method(变异方法)
- 短语:mutating func · nonmutating · value type
24. property wrapper
- 译:属性包装器 | Swift:封装属性读写逻辑、可复用的泛型类型
- 例
- A property wrapper reuses getter/setter logic. — 属性包装器复用 getter/setter 逻辑。
- @State and @Binding are property wrappers. — @State 和 @Binding 都是属性包装器。
- 地道:wrapped value(被包装值)
- 短语:wrappedValue · projectedValue · @State / @Binding
25. struct
- 译:结构体 | Swift:值类型的字段与方法聚合体
- 例
- A struct is a value type in Swift. — struct 在 Swift 中是值类型。
- Structs are copied on assignment. — struct 在赋值时被复制。
- 地道:value semantics(值语义)
- 短语:value type · memberwise initializer · struct vs class
26. type inference
- 译:类型推断 | Swift:编译器根据上下文自动推导表达式类型
- 例
- Swift uses type inference for let. — Swift 对 let 使用类型推断。
- Type inference keeps code concise. — 类型推断让代码更简洁。
- 地道:infer the type(推断类型)
- 短语:infer the type · type annotation · explicit type