Loading...
Loading...
Compare original and translation side by side
| Collection | Order | Duplicates | Use When |
|---|---|---|---|
| Array | Ordered | Allowed | Indexed access needed |
| Dictionary | Unordered | Keys unique | Key-based lookup |
| Set | Unordered | Not allowed | Uniqueness required |
| 集合类型 | 有序性 | 是否允许重复 | 使用场景 |
|---|---|---|---|
| Array | 有序 | 允许 | 需要索引访问时 |
| Dictionary | 无序 | 键唯一 | 基于键的查找 |
| Set | 无序 | 不允许 | 需要元素唯一性时 |
// Optional binding
if let value = optional { }
guard let value = optional else { return }
// Nil coalescing
let value = optional ?? defaultValue
// Optional chaining
let result = object?.property?.method()// Optional binding
if let value = optional { }
guard let value = optional else { return }
// Nil coalescing
let value = optional ?? defaultValue
// Optional chaining
let result = object?.property?.method()array.map { $0 * 2 } // Transform
array.filter { $0 > 0 } // Select
array.reduce(0, +) // Combine
array.compactMap { Int($0) } // Transform + remove nil
array.flatMap { $0 } // Flattenarray.map { $0 * 2 } // 转换
array.filter { $0 > 0 } // 筛选
array.reduce(0, +) // 合并
array.compactMap { Int($0) } // 转换+移除nil
array.flatMap { $0 } // 展平